Interpolate data between two specified contours
조회 수: 27 (최근 30일)
이전 댓글 표시
Hi,
I would like to interpolate the data between two selected contours (blue and violet lines in the attached plot).
How can I do that?
Thank you,
Carola
댓글 수: 0
채택된 답변
Star Strider
2023년 8월 28일
I am not certain what result you want. The easiest way is probably to use the contour function itself to interpolate.
Example —
x = linspace(50, 100, 50);
y = linspace(0.2, 0.6, 50);
z = x(:)*y
figure
[c1,h1] = contour(x, y, z, 'ShowText',1);
colormap(turbo)
% Lvls = h1.LevelList
hold on
[c2,h2] = contour(x, y, z, [1 1]*26.75, '--k', 'ShowText',1); % Draw Contour At Interpolation Level = 27.75
hold off
LevelInterp = array2table(c2(:,2:end).', 'VariableNames',{'X','Y'}) % (X,Y) Coordinates Of The Interpolated Line
Your data seem to be contonuous (only one contour at each level of interest) so this approach should work both to draw the contour and return the (x,y) coordinates of that contour if that is what you want to do. You can do this more than once for more interpolated levels, or get more than one interpolated contour in one call to contour (however that then requires a bit of straightforward — although nontrivial — coding to extract the (x,y) coordinates of each contour).
.
댓글 수: 2
Star Strider
2023년 8월 28일
편집: Star Strider
2023년 8월 28일
My pleasure!
Extracting all those values would not necessarily require using contour once you decided on the levels.
That might be simply something like this —
X = linspace(50, 100, 50);
Y = linspace(0.2, 0.6, 50);
Z = X(:)*Y
Lm = Z>=25 & Z<=30 % Logical Matrix Of Values Meeting Criteria
Ze = Z.*Lm;
for kc = 1:size(Ze,2)
Zm{:,kc} = Ze(Ze(:,kc)~=0,kc);
end
Zmnzc = cellfun(@(x)any(x~=0,1), Zm, 'Unif',0); % Logical Index Of Non-Zero Entries
Zmnz = Zm([Zmnzc{:}]) % Cell Array Of Noin-Zero Entries
Column_Means = cellfun(@mean, Zmnz)
This finds all the values for ‘Z’ meeting the criteria, and then (since there might be different numbers of elements in each row or column) isolates the columns with at least one non-zero value and then takes the mean of each column. The grand mean would then be the means off all those, in this instance:
GrandMean = mean(Column_Means)
EDIT — (28 Aug 2023 at 22:21)
Another option of course is to just do —
GrandMean = mean(Z(Lm))
.
추가 답변 (1개)
Matt J
2023년 8월 28일
편집: Matt J
2023년 8월 28일
We don't know in what form your input data exists. Most of the contour plotting functions allow you to specify the isocontour level that you want computed. To interpolate, you would just choose a level that lies between the levels of the blue and violet lines.
댓글 수: 2
Matt J
2023년 8월 28일
편집: Matt J
2023년 8월 28일
One possibility would be to use contourc
C = contourc(Time,Frequency,Z,target_level)
You can extract x,y coordinates from the contour matrix C using getContourLineCoordinates from this FEX download,
https://www.mathworks.com/matlabcentral/fileexchange/74010-getcontourlinecoordinates?s_tid=srchtitle
contourTable = getContourLineCoordinates(C)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!