필터 지우기
필터 지우기

How to display coordinates of points in "contourf"?

조회 수: 13 (최근 30일)
Ali Baig
Ali Baig 2018년 8월 6일
답변: Afshin Aghayan 2019년 10월 8일
I have three matrices, X, Y, and Z. I am creating a filled contour plot using the command
contourf(X,Y,Z)
How can I display the coordinates of all points in the plot? I can use "Data Cursor" in figure environment to mark coordinates of points individually but this may take a lot of time depending on the number of points.
  댓글 수: 4
jonas
jonas 2018년 8월 6일
Still unclear. Do you want to overlay the contourf with a grid showing all coordinates, like [x1,y1]? All coordinates included?
Ali Baig
Ali Baig 2018년 8월 6일
Yes! this is exactly what I want to do. Thank you!

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

채택된 답변

jonas
jonas 2018년 8월 6일
편집: jonas 2018년 8월 6일
It's going to look real messy when you have high resolution x and y data.
%%Some data
[x,y,z]=peaks(20);
[~,c]=contourf(x,y,z);hold on
set(gca,'XTick',[],'YTick',[]);
%%Create cell array with coordinates
C = reshape([x(:)'; y(:)'], [], 1)';
str=sprintf('[%.2g;%.2g],',C);
str=strsplit(str,',')
str(end) = [];
%%Plot labels
text(x(:),y(:),str(:),'fontsize',6,'horizontalalignment','center','verticalalignment','mid')
Or alternatively, with the undocumented sprintfc (courtesy Walter Roberson)
%%Same code as above, until:
str=sprintfc('[%.2g;%.2g]',C);
text(x(:),y(:),str(:),'fontsize',6,'horizontalalignment','center','verticalalignment','mid')
  댓글 수: 4
Walter Roberson
Walter Roberson 2018년 8월 6일
sprintfc() might come in handy. Unfortunately it is undocumented.
jonas
jonas 2018년 8월 6일
편집: jonas 2018년 8월 6일
Managed to do it with sprintf, although it was a bit of a hassle. Will definitely look into sprinfc! Thanks

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

추가 답변 (1개)

Afshin Aghayan
Afshin Aghayan 2019년 10월 8일
you can use this code for displaying any data in the form of [x, y, f(x,y)] or data with coordinate

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by