How to force an external figure in live scripts?

611 ビュー (過去 30 日間)
Alex
Alex 2016 年 10 月 13 日
コメント済み: Walter Roberson 2024 年 3 月 8 日
I recently got R2016b and have been using live scripts. It is interesting how outputs are capable of being embedded inline (or to the right of) the code, but find it cumbersome to work with while debugging. For example, below is a picture of a simple live script with both a graph and text being printed.
Is it possible to force live scripts to behave like standard scripts in terms of output? So, the figure would start as its own window and the text printed to the command window?
If you hover over the figure, it has an option to "Open in figure window" but I would prefer a programmatic way to accomplish this, so I don't have to do this every time.
I realize I could just go back to standard scripts, but like the ability to put headings, text, and equations inline with the code. In other words, can I disable the live script output behavior while keeping all of its other benefits?
Thanks

採用された回答

Marshall
Marshall 2016 年 12 月 16 日
Use the following command:
set(gcf,'Visible','on')
Neither select and F9, nor the Run command work for me because highlighting large sections to run F9 is tedious, and the Run command doesn't create the figure in a standard figure window. In addition, if I run more plot commands on those figures outside of the live script, then the figure window remains hidden, and I don't see those changes. This way shows the figure window, and saves the figure result with the live script.
clc;
clear;
close all;
x=(0:0.01:2*pi)';
y=sin(x);
fprintf('\nPrinting graph...');
figure;
set(gcf,'Visible','on')
plot(x,y);
fprintf('done.');
  5 件のコメント
Aditya
Aditya 2023 年 2 月 14 日
Minor point, for anyone coming here with a handle to figure, something like this:
f = figure;
You will need to set f and not gcf to get expected behaviour. Do something like this
set(f, 'Visible', 'on');
Walter Roberson
Walter Roberson 2024 年 3 月 8 日
Chang gao chang gao comments
解决了我的难题
(which approximately translates as "solved my problem")

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

その他の回答 (2 件)

Pico Technology
Pico Technology 2016 年 10 月 14 日
Hi Alex,
I've found that you can select the live script in the MATLAB Current Folder view and select F9 to run it as a script or right-click and select Run.
Hope this helps.

sunny Yang
sunny Yang 2020 年 1 月 30 日
編集済み: sunny Yang 2020 年 1 月 30 日
% Tested on Matlab 2019B,got the pop window and correct handle
% Mechanism:timers runs independently
function fig = ForcePopupFigure()
global NewFig;
tim = timer('TimerFcn',@temp,'ExecutionMode','singleShot');
tim.start();
pause(0.5);
fig = NewFig;
NewFig.Visible = 'on';
delete(tim);
end
function temp(~,~,~)
global NewFig;
NewFig = figure;
end

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by