필터 지우기
필터 지우기

reshaping data to fit contour plot requirements

조회 수: 4 (최근 30일)
Ravi
Ravi 2012년 11월 15일
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