Plot contours using discrete data points

Hi. I have three matrices (X, Y & Z) with X & Y contains x, y coordinates and Z contains value at this location. I plotted a coloured plot using "scatter function" as shown below. But I want to plot the similar diagram as contour plot not like colouring discrete points based on values. Please help

답변 (2개)

SALAH ALRABEEI
SALAH ALRABEEI 2021년 6월 5일

0 개 추천

% try this
contour(X,Y,Z)
or
% this
contourf(X,Y,Z)

댓글 수: 3

mukesh bisht
mukesh bisht 2021년 6월 5일
Using contour or contourf it shows following error
Error using contourf (line 57)
Z must be at least a 2x2 matrix.
Note: Let say i have 100 points so my matrices(X,Y & Z) are 100 x1
what is ur Z!! is it a function!!
mukesh bisht
mukesh bisht 2021년 6월 5일
No it is not a function. Corresponding to each point P(x,y), matrix Z contain a single discrete value

댓글을 달려면 로그인하십시오.

Star Strider
Star Strider 2021년 6월 5일

0 개 추천

Let say i have 100 points so my matrices(X,Y & Z) are 100 x1
They could be gridded already. If they are, then simply using reshape the same way on eadh vector will create the necessary matrices. The easiest way to determine that is to plot them as:
figure
stem3(X, Y, Z)
grid on
If they are gridded, the regularity will be immediately apparent.
Otherwise, do something like this —
xv = linspace(min(X), max(X));
yv = linspace(min(Y), max(Y));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(X, Y, Z, Xm, Ym);
figure
contourf(Xm, Ym, Zm)
axis('equal')
Providing that there are no serious prolbmes with the origina vectors, that should work.
.

댓글 수: 4

mukesh bisht
mukesh bisht 2021년 6월 6일
Thanks. It worked. But I have one more query. Can this contour be made more smoother i.e. instead of strips of colours can it be like that color changes from one to other very smoothly.
Without having your data to experiment with, that is difficult to determine.
One possibility is to increase the number of points in ‘xv’ and ‘yv’:
xv = linspace(min(X), max(X), 500);
yv = linspace(min(Y), max(Y), 500);
They now have increased from 100 to 500. Increase them further if this produces the desired result, and even smoother gradients are desired.
mukesh bisht
mukesh bisht 2021년 6월 6일
I have attached the data (X,Y,Z) matrix.
Having the data to experiment with made all the difference!
To make the contourf plot appear smoother, increase the number of contours. (I increased them to 200 here. Increase them further as desired.) The ‘steps’ are still there, there are simply more of them.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/643940/data.txt');
X = T1{:,1};
Y = T1{:,2};
Z = T1{:,3};
xv = linspace(min(X), max(X));
yv = linspace(min(Y), max(Y));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(X, Y, Z, Xm, Ym);
figure
contourf(Xm, Ym, Zm, 200, 'LineStyle','none')
colormap(turbo)
colorbar
axis('equal')
Rotating it and putting it in the circle would be possible, however I would need to know how you arrived at that.
.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

질문:

2021년 6월 5일

댓글:

2021년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by