clear all output code
417 次查看(过去 30 天)
显示 更早的评论
Is it possible in matlab live script to "clear all output" with a program code?
12 个评论
ga rec
2019-8-14
In the code is a loop and the live script should only present the output in the script after the second run.
Therefore I only want to erase the output in the script with a code; like it is possible with right-click anywhere in the script and select Clear All Output
Rik
2019-8-16
Despite the efforts from Mathworks to push people to use live scripts, I expect most power users will still use normal scripts and functions.
I would suggest you prevent your code from returning any output when you don't want it to, instead of resorting to clearing it. Something like the rudimentary example below.
A=zeros(1,4);
for n=1:2
A=A+rand(1,4);
if n==2
disp(A)
end
end
ga rec
2019-8-16
Thanks for the answer. I think I have to precisise my issue:
I have a lot of calculations and I want to display some of them at determined positions in the output where the required results are not calculated yet.
I think the easiest way with the least effort is to calculate the results in the first run of a loop and display them at the second run of the program. Therefore I need a solution to "Clear All Output" in the code. I think I need a handle for the "Clear all Output"-button, but I can't find one.
ga rec
2019-8-16
I'm looking for a code or handle to execute the "Clear all Output"-botton (marked in the photo below) in the program
Tom Pickering
2020-11-3
Hi, could you please give some more detials on the desired workflow? I am trying to understand when and why you want outputs to show, and when and why you want (some or all) outputs to clear in a Live Script.
Walter Roberson
2020-11-3
Recently someone asked about clearing livescript output. What they were looking for was a way to put some output (progress information) at the top of the screen, which can be done with the regular command window by clc;fprintf.
Neither the regular command window nor livescript permit a program to output to a particular screen location.
The usual workaround for progress information in the command window is to Carriage Return and write enough new output to erase what was previously on the line.
(I am not sure why waitbar is not used.)
Adam Danz
2020-11-3
In the Live Editor environment we have the option [Clear all Output] under the View tab. Many people, including myself, want to execute this programmatically. So, any workflow that includes that button is a workflow that could be done programmatically, if we had such a command.
For example, many people use a script to clear everything (example), to set Matlab to a clean state that removes all figures, clears all variables, and clears the command window. But when you're working with a Live Script, you have to take the extra measure of selecting the view tab > pressing the clear-all-output button.
Another example is when adding code to a live script after an embedded figure is produced, the new code goes under the figure until the live script regenerates the content. That's annoying but so is clicking on a tab and then a button to clear the content. Instead, I'd like to add the clear-live-script command to my existing shortcut that cleans up the matlab console.
I don't think an existing commands should clear the live script. Instead, I think there should be an additional command or flag to clear live scripts. That way live script content is only cleared intentionally. For example,
clear livescript
% or
cls
The functionality already exists and is invoked when the clear-all-output button is pressed. The new function or flag would do the same thing.
K.
2020-11-10
Regarding Walter's comment, I think I found the post where someone was trying to use clc and fprintf to show textual progress updates. If anyone is interested, I have posted a different workaround for textual progress indication that works in the Live Editor. Essentially, you can use the '\b' (backspace) character to remove characters from textual output in the Live Editor.
回答(2 个)
Heather Lai
2020-10-18
I would also like to encourage this functionallity. When I write code which I would like to operate iteratively after a user input, it would be very helpful for the output to be programatically cleared.
1 个评论
Chris Kloppers
2020-10-22
I also need to have this functionality. Mainly for good housekeeping, but I can think of many reasons why I would need it. It will even help to clear the output only for the current section.
Sai Bhargav Avula
2019-8-20
Currently you cannot programmatically set the clear output in Live Editor. There are only two ways to do this. First, the one you mentioned and the other by right clicking anywhere in the script and selecting the Clear All Output option.
20 个评论
ga rec
2019-8-20
Thanks for the answer.
Do you know a handle for the "Clear all Output"-button, so that i can implement this function in the code??
Sai Bhargav Avula
2019-8-20
编辑:Sai Bhargav Avula
2019-8-20
To the best of my knowledge it is not possible to create a handle for the Clear All Output. A possible work around, if there are no figures to be displayed would be to use the "evalc" function to redirect all the output displayed to a variable. The same way you redirect the outputs that are to be displayed on the command window.
Rik
2019-8-20
Using evalc has no advantage over the setup below and it has all the downsides of eval.
A=zeros(1,4);
for n=1:2
A=A+rand(1,4);
if n==2
disp(A)
end
end
ga rec
2019-8-20
Thanks for the answers.
@ Sai Bhargav Avula: I have a lot of figures in the output
@ Ric: I have the same idea Rik, but therefore i need a lot of additional code in the livescript environment and for presentation reasons it's not a solution for me with all the additional code.
Does nobody has an idea how to create a handle for the button?
Guillaume
2019-8-20
Typically, matlab does not give you programmatic access to its interface, so the answer to "how to create a handle for the button" is very likely: it's not possible.
There are some undocumented ways to hack into some of the interface (mostly the editor and command window) but as far as I know, there's no way to interact with the toolbar.
Adam Danz
2020-6-5
I also want a programmatic way to "Clear all outputs" in the live editor. I don't see why it would be so difficult to create a function similar to clc, clear, close for the live editor. Obviously the method already exists and is called when the "Clear all outputs" button is pressed so why can't there be a function that just calls upon that method? To me, this feature is an obvious one that's missing.
Michelle Hirsch
2020-10-9
Adam, could you say more about what you'd like to do with a programmatic clear all outputs?
Adam Danz
2020-10-9
编辑:Adam Danz
2020-10-11
I'd like to easily clear the embedded figures created in live script editor, programmatically. I realize there's a button that can be pressed but I would just like a function that evokes the same process. For example, I have a small script clr that looks something like this,
clear
close all
clc
and when I run that, I'd like the live script editor to be cleared of any embedded figures.
Sindar
2021-2-16
Here's my use case for a clear-livescript function: loop-plot-save
I have livescripts where the purpose is to:
- call other functions to create figures
- add to or combine these figures
- save new figures
Sometimes I need to play with a single figure, so livescript functionality is useful. Often, though, I've figured it out and want to loop over several figures. At the end of each loop, I'd like to clear output for a few reasons:
- livescripts occasionally do things I don't want, such as plotting in subplots of figures I didn't think had focus
- my figures often take up a lot of memory that I want cleared once they've been saved
- the livescript gets cluttered by the many figures and text output
Similarly, I sometimes need to loop over complicated plotting functions, but don't actually need the created plots. In some cases, I could easily adjust the functions themselves (e.g., add a "silent" option), but this isn't always feasible or worth my time
goc3
2021-5-19
I second Adam's comments here. I also have a custom script to run clear, close all, and clc, which I include in many .m files. Doing such things in .mlx files is not straightforward.
In particular, though, I am also needing a solution to the posted question/request for slightly a different reason. When using a live script to export a report (using Report Generator) that includes figures, it is preferable to have the figures closed/removed from the live script after being run. The figures end up in the generated report, where they are desired, but I'd rather keep the live script clear of all figures for easier readability and smaller file size.
Brent F
2021-6-23
Why is such basic functionality not allowed? There are many strange issues like this in Matlab that make it cumbersome to work with.
Christopher Wong
2022-12-10
Actually, I think the Clear All Ouput option is fine. IMO the Live Editor is not for hardcore automation—it's more of a supplementary GUI. I don't mind right-clicking as needed.
Marco Riani
2023-2-1
This is just to say that a lot of times I would have liked to clear the embedded figures created in live script editor, programmatically. It is mysterious the reason why you still cannot do it programmatically.
Jeremy Riousset
2023-3-24
I just wanted to vote that one up. I have the same request for the same reasons.
Gokhan Pekcan
2024-3-23
Obviously this is a much desired capability (which must already exists in another form); it's been requested for over three years... please...
Chen Wu
2024-3-31
I need this funtion, too, to let live script automatically remove previous outputs before new a calculation.
Jack
2024-5-9
I would also like this capability. Right clicking and picking Clear All Output is not a good solution. A code sequence similar to "clc" but for the live editor output window would be great. You could then assign it to the quick access toolbar for fast execution.
Thanks
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)