Finding Coordinates of Multiple Contours

1 回表示 (過去 30 日間)
Brian DeCicco
Brian DeCicco 2021 年 5 月 21 日
コメント済み: Adam Danz 2021 年 5 月 28 日
Hello, I am working with a dataset and trying to find the coordinates (lat/long) of each contour drawn from my loop. When I run the loop, each new iteration replaces the the previous position data of the last contour drawn, and I wish to get the position data for all 40 lines drawn contained within the same matrix. The position data of the line (and each line) should be stored under the variable "C" which is a 2 x ? double matrix. I appreciated any assistance you may be able to provide! Below is my code thus far:
for n = 1:40
[C,h] = contour(long3,lat3,squeeze(yearly_array2(:,:,n))',[287 287],'y');
end
  2 件のコメント
Adam Danz
Adam Danz 2021 年 5 月 21 日
編集済み: Adam Danz 2021 年 5 月 21 日
There are lots of functions on the file exchange that get the contour line coordinates.
Brian DeCicco
Brian DeCicco 2021 年 5 月 21 日
Thank you Adam, your response here was really helpful as well and I will try these in my coding!

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

採用された回答

KSSV
KSSV 2021 年 5 月 21 日
C = cell(40,1) ;
H = cell(40,1)
for n = 1:40 ;
[c,h] = contour(long3,lat3,squeeze(yearly_array2(:,:,n))',[287 287],'y');
C{n} = c ;
H{n} = h ;
end
celldisp(C)
  2 件のコメント
Brian DeCicco
Brian DeCicco 2021 年 5 月 21 日
Thank you! I very much appreciate your help. 1 final question based on this...if I wanted to loop through each point associated with each of the 40 contours and plot the max and min value y-values (i.e. lattitude) at each x-value (i.e. longitude) based on your code above, how would you recommend coding that up most efficiently?
Adam Danz
Adam Danz 2021 年 5 月 28 日
@Brian DeCicco There are some files on the file exchange that organize the contour matrix output into a table, a structure, or a cell array. Here's a list:

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2021 年 5 月 21 日
Why create the contours one at a time? Why not pass a vector of contour levels to the contour function and either parse the ContourMatrix property of the contour object or the contour matrix returned as the first output of contour? This will also eliminate the need to break the ambiguity of whether a scalar value represents a number of contours to plot or the height at which to plot one single contour line.
[X, Y, Z] = peaks;
surf(X, Y, Z);
hold on
[C, h] = contour3(X, Y, Z, -5:5, 'r'); % I could also have used surfc
shading interp
C(:, 1)
ans = 2×1
-5 25
This tells me the contour at z = -5 has 25 points.
C(:, 1+25+1) % 1 (first element) + 25 (points on first contour) + 1 (move to start of next contour)
ans = 2×1
-4 35
The contour at z = -4 has 35 points, etc.

カテゴリ

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