이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
clear all output code
조회 수: 405 (최근 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 (한국어)