Colormap color levels on cursor

I have a 3 column matrix which is x,y, and C. x and y values are coordinates and C value is intensity. I plot a diagram with using "patch" command.
On figure i just get x and y values on cursor. I want to see intenstiy values on colormap. How can i do it?
Note:
I have tried before meshgrid and countourf but it takes a lot of time to create figure because i have many data points. I use for loop for every rectangle so it takes a lot of time. When i do not use for loop it creates a wrong shape.
Anyone can help me?

3 Comments

Attach the data
You can write your own Data cursor function
doc datacursormode
shows an example of this if you look for the UpdateFcn. It isn't necessarily trivial though. You'd likely have to use the axes' CurrentPoint property and work out which patch is currently under the mouse.
Alternatively I guess you could program your own functionality entirely using the ButtonDownFcn property of the patch objects (or of the axes objects if you can work out which patch is under the mouse. Doing tis on the axes though would require the patches to have their 'HitTest' set to off, otherwise the axes won't pick up mouse clicks under patches).
hi darova,
here is my code,
a=load('a.txt');
cor=[a(:,1) a(:,2)];
m1=a(:,3);
ff=reshape( 1:length(cor), 4, length(cor)/4)';
figure
p=patch('Faces',ff,'Vertices',cor,'FaceVertexCData',m1,'FaceColor','interp')
colormap(flipud(jet(15)))
shading interp
colorbar
set(p, 'edgecolor','black')
i want to see 'FaceVertexCData',m1 values on plot with datacursor. i just see cor values as X and Y.
hi Adam,
i take a look your advice but i cant understand, i am new at matlab

Sign in to comment.

 Accepted Answer

Here is direction
You have position of cursor in variable pos
You can access to FaceVertexCData with command
get(h,'FaceVertexCData')
You can access to XY data too:
get(h,'Vertices')
So all you have to do is to find some connection between all this data. Find index of pos in Vertices data and use it to display FaceVertexCData
123.png

12 Comments

Thank you for your help but i cant understand how can i add my code that.
Can you help further more?
I tried to do this but i couldnt, what shoul i do with my code?
Can you sho wthe code you tried?
i added this line my code above
get(p,'FaceVertexCData')
that only shows values on command window.
then i tried to edit text update function but i couldnt.
i added this line in NewCallback.m:
h=get(event_obj,'FaceVertexCData');
get(h);
but i dont know how to use this .m file.
You have some points, each has number. You have another point and you want to find index for it. If you will find index you can find CData value for it.
Any ideas?
123.png 1223.PNG
a=load('a.txt');
cor=[a(:,1) a(:,2)];
m1=a(:,3);
ff=reshape( 1:length(cor), 4, length(cor)/4)';
figure
p=patch('Faces',ff,'Vertices',cor,'FaceVertexCData',m1,'FaceColor','interp')
colormap(flipud(jet(15)))
shading interp
colorbar
set(p, 'edgecolor','black')
in this code i have 'FaceVertexCData' as m1 matrix, i just want to see their values on plot when i move my cursor o plot.
In your first answer you can get X, Y and Cdata on plot, how can you do that?
Just add it to your CallBack function
h = get(event_obj,'target');
data = get(h,'vertices');
cdata = get(h,'FaceVertexCData');
D = pdist2(data,pos(1:2));
[~,ix] = min(D);
output_txt{end+1} = ['Cdata: ',num2str(cdata(ix),4)];
Thanks for your help darova but i can not do that. i am not a software engineer or computer engineer and i am new in matlab. what shoul i do create CallBack function. i just can write this code and it creates a figure. what should i do after creating figure. can you help?
a=load('a.txt');
cor=[a(:,1) a(:,2)];
m1=a(:,3);
ff=reshape( 1:length(cor), 4, length(cor)/4)';
figure
p=patch('Faces',ff,'Vertices',cor,'FaceVertexCData',m1,'FaceColor','interp')
colormap(flipud(jet(15)))
shading interp
colorbar
set(p, 'edgecolor','black')
hi again darova,
i save a Newcallback.m file and i can get values on figure with using Update Function.
02.jpg
my new question is, how can i make default way to use this function.
i try that but it doesnt work, 'ButtonDownFcn',@myfunction. here is my figure code.
figure
pm1=patch('Faces',ff,'Vertices',cor,'FaceVertexCData',m1,'FaceColor','interp','Selected','on','ButtonDownFcn',@myfunction);
colormap(flipud(jet(20)))
shading interp
colorbar
title('X MOMENT','FontSize',14)
set(pm1, 'edgecolor','black','LineWidth',0.5)
grid on
grid minor
which folder should i copy my Newcallback.m file and which command should i use?
Thanks for all your help, you are great :)
thank you darova,
where should i copy this .m file? i want to run this code when i open matlab everytime.
i have many data to plot, so i want to draw and get values every time when i run this code. actually i want to create a gui program with this.
ok darova,
i can do it now :)
i rename .m file and copy it my current directory so it runs :)
how can i do this function as matlab's default function. ehich folder should i copy?

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019b

Asked:

on 16 Oct 2019

Commented:

on 19 Oct 2019

Community Treasure Hunt

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

Start Hunting!