MATLAB - adding additional data to surface plot tooltip

I have created a cylinder with the help of a surface plot and a 360x512 matrix with some data(named map100).
When i put my cursor over the cylinder i see my X,Y,Z on the tooltip as expected. However i would also like to see the matrix(map100) value for that point on the tooltip as well. Is this possible ? and if so how?
Any help is much appreciated..

回答(1 个)

I just confirmed that surf() do have the needed property.

9 个评论

i see that but how do i extract the value from the map100 matrix for that point so i can display it?
row = dataTipTextRow('m100', map100);
cyl.DataTipTemplate.DataTipRows(end+1) = row;
I think.
i tried that and i get this error.
Error using matlab.graphics.datatip.DataTipTemplate/set.DataTipRows
{Value must be a string scalar or a character vector with the name of a data property, such as 'XData', or it must be a
vector or a function handle.
Error in createSurfCylinderFinal (line 36)
cyl.DataTipTemplate.DataTipRows(end+1) = row;}
im very confused
Works for me when I try in R2020b.
z = randi(9, 30, 50);
map100 = sort(z) + randn(size(z));
cyl = surf(z);
row = dataTipTextRow('m100', map100);
cyl.DataTipTemplate.DataTipRows(end+1) = row;
this is my map
function heat = getCylinderHeatMap(filename)
%Returns a struct with info about the file.
s = dir(filename);
%Opens a file for reading, hence the 'r'.
fin = fopen(filename,'r');
I=fread(fin,s.bytes,'uint8=>uint8');
w = uint16(I(1))+256*uint16(I(2));
h = uint16(I(3))+256*uint16(I(4));
skip = s.bytes - w*h + 1;
IN = I(skip:1:s.bytes);
Z=single(reshape(IN,w,h));
Z=griddedInterpolant(Z');
y_range = linspace(1.0,single(h),360);
x_range = linspace(1.0,single(w),512);
heat = uint8(Z({y_range, x_range}));
end
I do not have your file or your input matrix to test with, and I posted demonstration code that showed that my approach works.
What is size(map100) ? It looks most likely to be 2D to me, but I cannot prove it from what has been posted.
You could try
row = dataTipTextRow('m100', 'map100');
cyl.DataTipTemplate.DataTipRows(end+1) = row;
My workspace that stores all variables says map100 is a 360x512 uint8.
Did you try my sample code? Did it work for you?

请先登录,再进行评论。

类别

产品

版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by