user9512015
user9512015

Reputation:

how to plot a contour map using a matrix for X, Y and Z values?

M matrix is:

M = [0  5   10  15  20  25  30  35  40  45
5   0.0137945780000000  0.0140902780000000  0.0141900320000000  0.0142399090000000  0.0142897860000000  0.0143111620000000  0.0143289750000000  0.0143432260000000  0.0143503510000000
10  0.0211336350000000  0.0218034130000000  0.0220955500000000  0.0222238060000000  0.0223413730000000  0.0223983750000000  0.0224304390000000  0.0224731910000000  0.0224803160000000
15  0.0293099150000000  0.0304570880000000  0.0309416080000000  0.0311945560000000  0.0313833770000000  0.0314795680000000  0.0315330080000000  0.0315900100000000  0.0316113860000000
20  0.0383127290000000  0.0401261180000000  0.0408457730000000  0.0412590400000000  0.0415333640000000  0.0416723080000000  0.0417684990000000  0.0418468770000000  0.0418753790000000
25  0.0486978520000000  0.0512202070000000  0.0522711890000000  0.0528697140000000  0.0532758560000000  0.0534718020000000  0.0536249960000000  0.0537247500000000  0.0537746270000000
30  0.0601945210000000  0.0635255980000000  0.0649399690000000  0.0657807550000000  0.0663151520000000  0.0665859130000000  0.0667818590000000  0.0669172400000000  0.0669778050000000
35  0.0730877480000000  0.0774769320000000  0.0794007620000000  0.0804838080000000  0.0811927750000000  0.0815561650000000  0.0818411770000000  0.0819979340000000  0.0820976880000000
40  0.0854358900000000  0.0909188070000000  0.0933699100000000  0.0946987780000000  0.0955823150000000  0.0960347710000000  0.0963874740000000  0.0965834190000000  0.0967366130000000
45  0.0994477890000000  0.106052941000000   0.109099006000000   0.110823328000000   0.111820870000000   0.112383769000000   0.112818412000000   0.113057109000000   0.113228116000000];

How to plot a contour graph using the matrix M.. the first row and the first column of matrix M would be the coordinates for each value.. for example:

enter image description here

for the coordinates 5,5 the z value for the contour map would be 0.01379458 and for the coordinates 30,20 the z value would be 0.06578076. the idea is to plot all the coordinates of matrix M and use the z values for the contour plot.

What could be the best way to solve it?

Upvotes: 0

Views: 315

Answers (1)

ViG
ViG

Reputation: 1868

To plot a 3D contour you can use contour3. The x-values are given by M(1,2:end). This means first row, column 2 till the end. Same for the y-values M(2:end,1). The z is the rest of the matrix: M(2:end,2:end).

Full code:

M = [0  5   10  15  20  25  30  35  40  45
5   0.0137945780000000  0.0140902780000000  0.0141900320000000  0.0142399090000000  0.0142897860000000  0.0143111620000000  0.0143289750000000  0.0143432260000000  0.0143503510000000
10  0.0211336350000000  0.0218034130000000  0.0220955500000000  0.0222238060000000  0.0223413730000000  0.0223983750000000  0.0224304390000000  0.0224731910000000  0.0224803160000000
15  0.0293099150000000  0.0304570880000000  0.0309416080000000  0.0311945560000000  0.0313833770000000  0.0314795680000000  0.0315330080000000  0.0315900100000000  0.0316113860000000
20  0.0383127290000000  0.0401261180000000  0.0408457730000000  0.0412590400000000  0.0415333640000000  0.0416723080000000  0.0417684990000000  0.0418468770000000  0.0418753790000000
25  0.0486978520000000  0.0512202070000000  0.0522711890000000  0.0528697140000000  0.0532758560000000  0.0534718020000000  0.0536249960000000  0.0537247500000000  0.0537746270000000
30  0.0601945210000000  0.0635255980000000  0.0649399690000000  0.0657807550000000  0.0663151520000000  0.0665859130000000  0.0667818590000000  0.0669172400000000  0.0669778050000000
35  0.0730877480000000  0.0774769320000000  0.0794007620000000  0.0804838080000000  0.0811927750000000  0.0815561650000000  0.0818411770000000  0.0819979340000000  0.0820976880000000
40  0.0854358900000000  0.0909188070000000  0.0933699100000000  0.0946987780000000  0.0955823150000000  0.0960347710000000  0.0963874740000000  0.0965834190000000  0.0967366130000000
45  0.0994477890000000  0.106052941000000   0.109099006000000   0.110823328000000   0.111820870000000   0.112383769000000   0.112818412000000   0.113057109000000   0.113228116000000];

contour3(M(1,2:end),M(2:end,1),M(2:end,2:end))

with result

enter image description here

If you want more levels, you can specify a fourth input argument. e.g.

contour3(M(1,2:end),M(2:end,1),M(2:end,2:end),50) 

gives

enter image description here

Upvotes: 1

Related Questions