- Table output: https://www.mathworks.com/matlabcentral/fileexchange/74010-getcontourlinecoordinates
- Structure output: https://www.mathworks.com/matlabcentral/fileexchange/38863-extract-contour-data-from-contour-matrix-c
- Cell array output: https://www.mathworks.com/matlabcentral/fileexchange/43162-c2xyz-contour-matrix-to-coordinates
extracting all other variables on a contour level
5 views (last 30 days)
Show older comments
I have a x-y meshgrid with different variables in it. I plot a contour level of f1 using [c,h]=contour(x,y,f1,clev):
Now I need to save other variables like f2,f3,... only on the shown contour level of f1 (blue line) in a matrix.
3 Comments
Adam Danz
on 21 Jul 2020
The functions I mentioned do not calculate the x,y values. They only reorganize the c or h outputs of contour() by level. For example, using the first one in my list,
% Reorganize the contour outputs into a table.
[cm, h] = contour(x,y,f1,clev);
contourTable = getContourLineCoordinates(cm);
% Look at first few rows of the table (fake data)
% 4×4 table
% Level Group X Y
% ________ _______ _______ _______
% -5.8504 1 0.44266 -1.75
% -5.8504 1 0.375 -1.8038
% -5.8504 1 0.25 -1.8526
% -5.8504 1 0.125 -1.8498
% Get the index for all rows at level #7 (you could also index by group number)
levelIdx = contourTable.Level == h.LevelList(7);
% or
% levelIdx = contourTable.Group == 7;
% Use the x and y values
x(levelIdx)
y(levelIdx)
Answers (0)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!