How to display coordinates of points in "contourf"?
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ali Baig
el 6 de Ag. de 2018
Respondida: Afshin Aghayan
el 8 de Oct. de 2019
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 comentarios
jonas
el 6 de Ag. de 2018
Still unclear. Do you want to overlay the contourf with a grid showing all coordinates, like [x1,y1]? All coordinates included?
Respuesta aceptada
jonas
el 6 de Ag. de 2018
Editada: jonas
el 6 de Ag. de 2018
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 comentarios
Walter Roberson
el 6 de Ag. de 2018
sprintfc() might come in handy. Unfortunately it is undocumented.
Más respuestas (1)
Afshin Aghayan
el 8 de Oct. de 2019
you can use this code for displaying any data in the form of [x, y, f(x,y)] or data with coordinate
0 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!