Is there a contourc equivalent for contourm?

13 ビュー (過去 30 日間)
Mark Debord
Mark Debord 2022 年 3 月 10 日
編集済み: Walter Roberson 2025 年 11 月 21 日 7:44
Hello,
I would like to compute contours on geotiffs without producing a plot. For regular rectangluar data 'contour' will compute the contours and plot them, and 'contourc' function will just compute the contours and return the contour matrix without plotting. It appears the geographic contour function 'contourm' works like 'contour' and produces a plot, I would like to get the contours without generating a plot.
Right now my solution is this:
set(0,'DefaultFigureVisible','off');
altContour = contourm(geoData,geoRef,'LevelList',geoAltitude,'Visible','off');
close(gcf);
set(0,'DefaultFigureVisible','on');
But this is still incurring overhead penalties for setting up the figure... I would ideally like a function like 'contourmc'. Is there some function, even internal or undocumented, that I can use to achieve this?
  1 件のコメント
Andrew Wind
Andrew Wind 2025 年 11 月 20 日 19:27
I have also been using a similar method to suppress making the figure visible and then closing it, but this doesn't answer the original question.
Is there another function or option that will calculate the result without the overhead of plotting an invisible figure in the background?

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

回答 (2 件)

Pavan Sahith
Pavan Sahith 2023 年 10 月 12 日
Hi Mark,
I understand you would like to compute contours on geotiffs without producing a plot.
You can use the ‘contourm’ function in this way to achieve the contour matrix without plotting.
% Example data
[X, Y, Z] = peaks;
% Define the desired contour levels
contourLevels = [-5, -3, -1, 1, 3, 5];
% Create a temporary invisible figure to capture the contour data
hFig = figure('Visible', 'off');
% Use contourm to capture the contour data
[ccontourData] = contourm(Y, X, Z, contourLevels)
ccontourData = 2×504
-5.0000 0.6250 0.5522 0.5000 0.3750 0.2500 0.1250 0.0376 0 -0.1182 -0.1250 -0.1893 -0.1978 -0.1335 -0.1250 0 0.1250 0.2500 0.3750 0.5000 0.5191 0.6240 0.6250 0.6594 0.6424 0.6250 -3.0000 -1.3750 -1.4003 -1.3938 25.0000 -1.4696 -1.3750 -1.3385 -1.2959 -1.2973 -1.3326 -1.3750 -1.3997 -1.5000 -1.5106 -1.6250 -1.7500 -1.8750 -1.8831 -1.9593 -1.9912 -1.9893 -1.9564 -1.8900 -1.8750 -1.7500 -1.7472 -1.6250 -1.5000 -1.4696 7.0000 0.2817 0.2500 0.1250
% Close the temporary figure
close(hFig);
% contourData contains the contour lines and levels without displaying the plot
Please refer to the MathWorks Documentation to know more about
Hope it helps .

Walter Roberson
Walter Roberson 2025 年 11 月 21 日 7:43
編集済み: Walter Roberson 2025 年 11 月 21 日 7:44
You can make the contourm() call within a Process based parallel pool (such as using parfeval()).
This has notable overhead... but no visible figure will be generated.
Note: contourm() is not supported on backgroundPool

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by