Datacursor in a for-loop surface plot

조회 수: 2 (최근 30일)
Habbenzak
Habbenzak 2015년 10월 30일
답변: Nitin Khola 2015년 11월 3일
Dear Matlab users,
I am plotting a surface of temperatures over a time period i. For every step in i, an image is created. I want to add a datacursor to every plotted image on coordinates x=34, y=1 and Z (dependent on every step in i). What do i add to my code to get this?
% code
surf(U(:,:,i+1));
zlabel('Temperature ^{\circ}C');
xlabel('x distance mm');
ylabel('y distance mm');
title('Surfplot of heattransfer in zeolite beads');
axis([0 34 0 34 0 200])
M(i)=getframe(gcf);
baseFileName = sprintf('Heattransfer_%d.png', i);
saveas(gcf, baseFileName, 'png')
end
Also, i want to show on what timestep the frame is. So, show i in the current surfplot. How can i get this?
Thanks in advance!
  댓글 수: 1
Habbenzak
Habbenzak 2015년 10월 30일
Okay, so i managed to get the surfplot to show the timestep using the following code:
% code
%# delete the previous annotation
delete(findall(gcf,'tag','timestep'))
%# create new annotation
annotation('textbox',...
[0.72 0.68 0.18 0.16],...
'String',{'time',i*dt 'sec',},...
'FitBoxToText','on',...
'tag' , 'timestep');
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Nitin Khola
Nitin Khola 2015년 11월 3일
You can use the "text" object to place your text at a specific data point in your plot. In your case, I think the text contains just the position information. Within the loop you can update the "Position" and "String" properties of the text object as per your desire. Here is some sample code that illustrates the idea.
fig = figure;
surf(peaks)
t = text(0,0,0,'start')
for ind = 1:10
z = ind;
t.Position = [30 40 z];
t.String = ['x= ' num2str(30) ' ' 'y= ' num2str(40) ' ' 'z= ' num2str(z)];
pause(0.1) % Make it visible to us.
end
Refer to the following documentation for details on "text". http://www.mathworks.com/help/matlab/ref/text.html?searchHighlight=text

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by