フィルターのクリア

Live Editor Output on the same line

47 ビュー (過去 30 日間)
Stefano Zontone
Stefano Zontone 2020 年 10 月 23 日
コメント済み: Bruce 2024 年 5 月 22 日
I have a loop in my code and I would like to print the temperature value until it is outside a specific range.
while ~temp_ok
pause(1);
clc;
fprintf('Temperature = %0.1f °C \n',ReadTemperature);
if (abs(ReadTemperature - TargetTemperature) < TEMP_TOLERANCE )
temp_ok = true;
end
end
The output window shows a line for each loop iteration:
Temperature = 22.8 °C
Temperature = 22.8 °C
Temperature = 22.8 °C
...
Is it possible to program Live Editor to print the output strings to the same line? With the previous editor it was very easy...
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 10 月 23 日
編集済み: Walter Roberson 2020 年 10 月 23 日
I notice the clc there which would clear the command window each iteration. I suspect that you are therefore wanting to overwrite a fixed output position on the screen -- is that correct?
Stefano Zontone
Stefano Zontone 2020 年 10 月 23 日
Yes, correct.
Pls, notice I am referring to Live Editor Output. I used a similar script with the standard editor and the output on the Command Window was ok. The clc command doesn's seem to work with Live Editor Output and I don't find a way to overwrite the previous output string with the updated one.

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

採用された回答

Walter Roberson
Walter Roberson 2020 年 10 月 23 日
There is no publicly known way to do what you are asking.
In recent discussions about related issues (having to do with removing plots), Mathworks staff have said they will ask the developers to provide methods. The response was not entirely clear as to whethere there is no internal method at the moment, or if there is an internal method but there is no public interface to it.

その他の回答 (2 件)

K.
K. 2020 年 11 月 10 日
While there is currently no way to programmatically clear the output in the Live Editor, the following (copied from another post of mine) might help. Some people have used the ‘\b’ (backspace) character to create textual progress indicators (e.g. https://blogs.mathworks.com/loren/2007/08/01/monitoring-progress-of-a-calculation/). I believe there are some tools for this on File Exchange, but as an example, you could do something like the following. Note that this is a crude example only meant to demonstrate the concept.
for ind=1:20
pause(.1)
printStatus(ind) % Do the fprints in a local function so that all the textual output is coming from one line in the script.
end
function printStatus (ind)
if ind == 1
% The very first time we don't need to delete the old text
fprintf('Last processed sample: %5d', ind);
else
% Each \b removes one character from the previous fprintf.
fprintf('\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bLast processed sample: %5d', ind);
end
end
Textual Progress Indication
  1 件のコメント
Stefano Zontone
Stefano Zontone 2020 年 11 月 20 日
Thank you for your suggestion...it sounds good for my needs.

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


Stefano Zontone
Stefano Zontone 2020 年 10 月 23 日
Hi Walter,
thank you for your answer.
I hope Mathworks will soon improve Live Editor functionalities...I find it very interesting and useful.
BR
S
  1 件のコメント
Bruce
Bruce 2024 年 5 月 22 日
There seems to be no improvement as of 2024.

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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by