フィルターのクリア

Matlab live script does not output the same as regular script.

12 ビュー (過去 30 日間)
Dan Po
Dan Po 2016 年 10 月 16 日
コメント済み: K. 2020 年 5 月 13 日
This script run as live script does not run the same as running as normal script. It runs as expected as normal script, but with live script it seems that the outputs lag behind by one run. Would there be a script fix to run this as wanted as a .mlx type?
clear
clc
orig='Jmkyvih$mx$syx$}ixC';
fprintf('original input is ''Jmkyvih$mx$syx$}ixC''\n')
yn=0;
counter=0;
while yn==0
yn= input('enter ''1'' to end the process or ''0'' to continue the loop\n');
if yn==1
fprintf('conversion found, %.0f loops were run to make the text readable\n',counter)
fprintf('string run %1.0f is "%s" \n\n',counter,orig)
break;
elseif yn~=0
error('restart and input a valid number')
else
end
fprintf('conversion not found\n ')
counter=counter+1;
orig=char(double (orig)-1);
fprintf('string run %1.0f is "%s" \n\n',counter,orig)
end
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 10 月 16 日
Interesting, I see what you mean.
Dan Po
Dan Po 2016 年 10 月 19 日
the .m output for the first entry is:
original input is 'Jmkyvih$mx$syx$}ixC'
enter '1' to end the process or '0' to continue the loop
0
conversion not found
string run 1 is "Iljxuhg#lw#rxw#|hwB"
The output of the first '0' entry in the .mlx file is white space. The first output is then displayed after the second input is entered.
I am confused as to why this occurs, and if it will cause problems for me in the future. for somew

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

採用された回答

K.
K. 2017 年 3 月 1 日
This is a known issue that we plan to address.
As a workaround, you can add a pause immediately preceding the “input” command. For example:
...
while yn==0
pause(0.1); %Temporary workaround so that all outputs up to this point are displayed.
yn= input('enter ''1'' to end the process or ''0'' to continue the loop\n');
...
This issue occurs because even though the code before the “input” command has executed, the Live Editor does not have a chance to show the output of the code until after the “input” command is executed. This results in the delayed behavior you are describing. By adding the short pause, the Live Editor is able to display outputs before the “input” command is executed.
  2 件のコメント
Mate D
Mate D 2020 年 5 月 13 日
Are there any updates (or at last workarounds) on this issue ?
K.
K. 2020 年 5 月 13 日
This issue is fixed in R2020a.
If upgrading is not an option, another possible workaround is to run the live script from the Command Window. To do so, type the file name in the Command Window. When you run a live script from the Command Window, output displays in Command Window instead of in the live script. The timing results, however, should be similar to those of a plain code (regular) script.

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

その他の回答 (1 件)

Prasad Mendu
Prasad Mendu 2016 年 10 月 19 日
Could you elaborate more on what do you mean by "lag behind by one run"?

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by