reshaping data to fit contour plot requirements

7 Ansichten (letzte 30 Tage)
Ravi
Ravi am 15 Nov. 2012
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.

Akzeptierte Antwort

Akiva Gordon
Akiva Gordon am 15 Nov. 2012
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.

Weitere Antworten (1)

Ravi
Ravi am 15 Nov. 2012
Bearbeitet: Ravi am 15 Nov. 2012
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

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by