필터 지우기
필터 지우기

How can I draw contour lines in my problem ?

조회 수: 2 (최근 30일)
Behrooz Daneshian
Behrooz Daneshian 2023년 2월 6일
편집: Voss 2023년 2월 8일
Hi all,
I have created cell array(which is attached here) in which the first and second columns representing latitude and longitude of each weather station exisitng in the Alaska state. The third column is the probability that freezing depth in that station exceeds 1 feet. What I want to do is plot contour lines represing the probability values. Can anyone help me with regard?

채택된 답변

Voss
Voss 2023년 2월 6일
load Behi1
data = cell2mat(POFDE1);
I = scatteredInterpolant(data(:,[1 2]),data(:,3));
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
[lat,lon] = meshgrid(unique(data(:,1)),unique(data(:,2)));
contour(lon,lat,I(lat,lon),'ShowText','on')
colorbar
  댓글 수: 9
Behrooz Daneshian
Behrooz Daneshian 2023년 2월 8일
Thank you so much. Your second solution worked for me.
Another question, in some point on the maps where contours overlape, the numbers on them can be rarely visible.(please see the attached map). Do you have any idea on How I can scale my maps?
Voss
Voss 2023년 2월 8일
편집: Voss 2023년 2월 8일
I don't know of a way to guarantee that the labels will always be legible, but you can try changing the LabelSpacing and/or TextStep properties, or set ShowText to 'off' to turn off the text labels entirely.

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

추가 답변 (2개)

Divyank
Divyank 2023년 2월 6일
The contour plot requires z-coordinates to be specified as a matrix and this matrix must have at least two rows and two columns, and it must contain at least two different values. However, the z-coordinates in POFDE1 is 1x273 cell array, according to my understanding of your problem, you can consider using plot3(X, Y, Z) instead of contour after extracting X, Y and Z co-ordinates from POFDE1 cell array in the following way:
% The input needs to be a scalar, vector or a matrix, hence conversion from
% cell array to vector is needed in this case, you might want to construct
% a matrix instead of a cell array to avoid this conversion.
X = cell2mat(POFDE1(:, 1));
Y = cell2mat(POFDE1(:, 2));
Z = cell2mat(POFDE1(:, 3));
plot3(X, Y, Z, '.');
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 2월 6일
The user specifically asked for contour lines. Voss shows one way of doing scattered contour.

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


Walter Roberson
Walter Roberson 2023년 2월 6일
https://www.mathworks.com/matlabcentral/fileexchange/38858-contour-plot-for-scattered-data is a File Exchange contribution for contour lines for scattered data.
You would probably still need to use cell2mat() like @Voss showed.

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by