フィルターのクリア

contour plot based on xyz data

110 ビュー (過去 30 日間)
SGMukherjee
SGMukherjee 2018 年 9 月 27 日
編集済み: Adam Danz 2020 年 3 月 9 日
I have xyz data as attached. X is longitude, y is altitude and z is electron density. For each value of longitude from 75 to 95, I have altitude values of 100 to 2000 with corresponding electron density values for each altitude. I want a colored contour plot with these data. Please help.

採用された回答

Star Strider
Star Strider 2018 年 9 月 27 日
Your data are gridded. You only need to reshape them into your ‘X’, ‘Y’, and ‘Z’ matrices:
D = load('data_new.txt');
[Du,D1] = unique(D(:,1));
Dd = diff(D1);
Dr = reshape(D, Dd(1), [], size(D,2));
X = Dr(:,:,1);
Y = Dr(:,:,2);
Z = Dr(:,:,3);
figure
contourf(X, Y, Z)
See the documentation on contourf (link) for details on how to customise it.
  2 件のコメント
wadah mahmoud
wadah mahmoud 2020 年 3 月 8 日
Dear Star Strider
Thank you for the providing code, I used it and it is very helpful for me but i need your assiatnce in " how to calculatethe maximum point and showing it on the plot" , if you need I will provide you a text file of values.
Thank you for assistance.
Wadah
Adam Danz
Adam Danz 2020 年 3 月 9 日
編集済み: Adam Danz 2020 年 3 月 9 日
"how to calculatethe maximum point and showing it on the plot"
[maxY, maxX] = find(Z == max(Z(:)));
hold on
plot(X(maxX), Y(maxY), 'rx')
If you'd like to select the entire contour that surrounds the max value, you can use getContourLineCoordinates() from the file exchange like so,
cm = contourf(X,Y,Z);
contourTable = getContourLineCoordinates(cm);
maxLevel = max(contourTable.Level);
xMaxLevel = contourTable.X(contourTable.Level == maxLevel);
yMaxLevel = contourTable.Y(contourTable.Level == maxLevel);
hold on
plot(xMaxLevel, yMaxLevel, 'r.', 'MarkerSize', 10)

サインインしてコメントする。

その他の回答 (1 件)

jonas
jonas 2018 年 9 月 27 日
編集済み: jonas 2018 年 9 月 27 日
You just need to interpolate gridded data.
xyz=dlmread('data_new.txt');
x=xyz(:,1);
y=xyz(:,2);
z=xyz(:,3);
[X,Y]=meshgrid(min(x):max(x),min(y):max(y));
Z=griddata(x,y,z,X,Y);
contour(x,y,Z)
  2 件のコメント
youssef aider
youssef aider 2019 年 3 月 25 日
works but, still gives some fluctuations
Daniyal Altaf Baloch
Daniyal Altaf Baloch 2020 年 2 月 7 日
Hi Jonas. Your answer perfectly works except for the typo in the last line.
Instead of
contour(x,y,Z)
it should be
contour(X,Y,Z) i.e capital X and Y will work .

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by