block plotting a figure

22 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2022 年 12 月 28 日
回答済み: Image Analyst 2022 年 12 月 28 日
Hi! I have a function A that calls other functions B, C, etc. Each function generates several plots, but in the end function A only plots one figure.
How can I not display the figure that function A generates without commenting on all the plots in the functions?

採用された回答

Image Analyst
Image Analyst 2022 年 12 月 28 日
You say "Hi! I have a function A that calls other functions B, C, etc. Each function generates several plots, but in the end function A only plots one figure.
How can I not display the figure that function A generates without commenting on all the plots in the functions?"
So A calls B and C, which both produce plots that you want to keep, and then after those calls A produces it's own plot that you do not want to display. So simply comment out the line in function A only that creates the figure. Or else set a flag, like
plotIt = false;
if plotIt
hfigA = figure('Name', 'Created by A'); % Create new figure in A and save its handle.
plot(xA, yA, 'b-'); % Plot something.
end
That would allow the B and C figures, which you want, to stay there.
Conversely, if you want everything except the A figure to be gone, then close them. If you know their handles you can do
close(hFigB);
close(hFigC);
If you don't, you can put this right before you plot the A plots
close all;
Then the plots from B and C won't be there and you can then decide whether to plot A's plot or not as I showed above.

その他の回答 (1 件)

Adam Danz
Adam Danz 2022 年 12 月 28 日
This is a common problem which often arises from functions that produce sanity-check visualizations or other windows to underlying data along the analysis pipeline. It's a good practice and the plotting code should be kept around for future referencing.
To optionally prevent figures from being produced, you can set a logical flag that can be set to true/false at the top of your script or function that determines whether the figures will be produced.
Here are two answers to similar questions that explain the flag solution and other ideas:

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by