How to plot contour map of x,y values with z as dependent variable?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Star Strider
on 16 Aug 2021
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 Comment
Star Strider
on 16 Aug 2021
Edited: Star Strider
on 16 Aug 2021
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')
.
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!