Clear Filters
Clear Filters

How to plot contour map of x,y values with z as dependent variable?

2 views (last 30 days)
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?

Accepted Answer

Star Strider
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)]
M = 6×6
NaN 1.0000 2.0000 3.0000 4.0000 5.0000 10.0000 0.1426 0.7396 0.1168 0.4759 0.4812 11.0000 0.1047 0.4046 0.8387 0.3730 0.0070 12.0000 0.5245 0.1428 0.2115 0.9163 0.1145 13.0000 0.6594 0.1435 0.4333 0.7755 0.3038 14.0000 0.2904 0.7174 0.1046 0.4741 0.7642
y = M(1,2:end)
y = 1×5
1 2 3 4 5
x = M(2:end,1)
x = 5×1
10 11 12 13 14
z = M(2:end, 2:end)
z = 5×5
0.1426 0.7396 0.1168 0.4759 0.4812 0.1047 0.4046 0.8387 0.3730 0.0070 0.5245 0.1428 0.2115 0.9163 0.1145 0.6594 0.1435 0.4333 0.7755 0.3038 0.2904 0.7174 0.1046 0.4741 0.7642
figure
contourf(x, y, z)
.
  1 Comment
Star Strider
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)]
M = 7×6
NaN 1.0000 2.0000 3.0000 4.0000 5.0000 10.0000 0.6555 0.6191 0.5899 0.8573 0.7831 11.0000 0.0481 0.1052 0.5465 0.1077 0.0505 12.0000 0.6671 0.3507 0.2023 0.8569 0.7675 13.0000 0.1031 0.1855 0.0567 0.1779 0.8689 14.0000 0.7443 0.6684 0.2625 0.3884 0.1757 15.0000 0.4330 0.4226 0.6579 0.2153 0.9822
y = M(1,2:end)
y = 1×5
1 2 3 4 5
x = M(2:end,1)
x = 6×1
10 11 12 13 14 15
z = M(2:end, 2:end)
z = 6×5
0.6555 0.6191 0.5899 0.8573 0.7831 0.0481 0.1052 0.5465 0.1077 0.0505 0.6671 0.3507 0.2023 0.8569 0.7675 0.1031 0.1855 0.0567 0.1779 0.8689 0.7443 0.6684 0.2625 0.3884 0.1757 0.4330 0.4226 0.6579 0.2153 0.9822
figure
contourf(x, y, z.')
xlabel('x')
ylabel('y')
.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!