reshaping data to fit contour plot requirements

5 次查看(过去 30 天)
Hello All,
I have data in x,y,z format where x is 30:70, y is 15:45 (both unit spacing), and with one z point per x,y pair. Each is a 1271x1 vector. plot3 and stem3 work just fine with that format.
contour is different and, while I can create a meshgrid for x and y, I am not quite getting how to reshape z to fit the requirements of the routine. Future datasets will have different sizes so I'm trying to get a good understanding of what contour requires versus hardwiring something for this specific case.
I'm sure that this is covered somewhere but I can't find it in the Matlab docs, this forum's archives, or the Usenet.
Pointers to an M to RTF greatly appreciated.

采纳的回答

Akiva Gordon
Akiva Gordon 2012-11-15
This strongly depends on how the data in "z" is stored. If the first 31 values in "z" represent the values for x = 30 & y = 15:45, and the next 31 values in "z" correspond to x = 31 & y = 15:45, etc., then it seems to me that you would likely get the result you are looking for by trying the following (assuming z is defined in the workspace):
x = 30:70;
y = 15:45;
[X,Y] = meshgrid(x,y);
Z = reshape(z,numel(y),numel(x));
contour(X,Y,Z)
If the data in "z" is stored differently, it would be helpful if you described how it is stored there.

更多回答(1 个)

Ravi
Ravi 2012-11-15
编辑:Ravi 2012-11-15
11/15/12 update: The answer worked and marked as accepted. Thank you.
========== Yes, the data are in the form you described; first x value, cycle through y, z as a function of x,y, etc.
Future datasets will follow the same format although exact sizes will be different. I look forward to trying the answer in the morning and think I understand the reshape sequence you suggested!
Thanks for the fast reply.
--- Ravi

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by