How to plot contour map of x,y values with z as dependent variable?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have this data where my Z is is the dependent variable for corresponding x and y. I need to import the data from excel and plot a contour color map
Can someone help please?
댓글 수: 0
채택된 답변
Star Strider
2021년 8월 16일
If ‘M’ is the matrix in the image:
y = M(1,:)
x = M(:,1)
z = M(2:end, 2:end);
So for example:
M = [NaN 1 2 3 4 5; 10 rand(1,5); 11 rand(1,5); 12 rand(1,5); 13 rand(1,5); 14 rand(1,5)]
y = M(1,2:end)
x = M(2:end,1)
z = M(2:end, 2:end)
figure
contourf(x, y, z)
.
댓글 수: 1
Star Strider
2021년 8월 16일
편집: Star Strider
2021년 8월 16일
My pleasure.
The matrix does not have to be square. However, the lengths of the vectors of ‘x’ and ‘y’ have to match the size of the matrix.
However, if you want me to help you with it, you need to provide it in a form I can works with. My version of MATLAB cannot run images of code or data, only the actual code or data.
EDIT — (16 Aug 2021 at 21:06)
Same idea, however with non-square matrix —
M = [NaN 1 2 3 4 5; 10 rand(1,5); 11 rand(1,5); 12 rand(1,5); 13 rand(1,5); 14 rand(1,5); 15 rand(1,5)]
y = M(1,2:end)
x = M(2:end,1)
z = M(2:end, 2:end)
figure
contourf(x, y, z.')
xlabel('x')
ylabel('y')
.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!