[Simple Q] Showing a Z value on a 2D plot datatip? scatter(X,Y,S,C)

2 views (last 30 days)
Hi, I am an entry-level, self-taught MatLab user with only VBA as part of my programming backround. I currently have a 2D scatter plot with colored dots as an intensity value :
function altitude(X,Y,Z)
fh = figure;
scatter(X,Y,15,Z,'o','fill')
axis('equal','tight')
colorbar
dcm = datacursormode(fh);
datacursormode on
set(dcm, 'updatefcn', @showalt)
function output_txt = showalt(obj,event_obj)
% Display the position of the data cursor
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
pos = get(event_obj,'Position');
output_txt = {['X: ',num2str(pos(1),4)],...
['Y: ',num2str(pos(2),4)]};
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
end
The problem is, since it isn't a 3D plot, the 'Z' value isn't showing up on the datatip.
What would be an effective way ,yet simple to understand, to get the according value from the 'Z' row vector and show it on the datatip?
Thanks, Étienne

Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!