フィルターのクリア

How to display a message as flashing and in my desired color and font size?

17 ビュー (過去 30 日間)
Sadiq Akbar
Sadiq Akbar 2023 年 2 月 1 日
コメント済み: DGM 2023 年 2 月 1 日
I want to display the following message in flashing and in my desired color and font size:
" Yes, the error is the same "
I am coding like this but it gives error:
disp('Yes, the error is the same','r','fontsize',5)
  4 件のコメント
prasanth s
prasanth s 2023 年 2 月 1 日
figure;
t=text(0.1,0.5,'text here','fontname','Courier','fontsize',30,'color','red');
for i=1:10
if mod(i,2)==0
t.Visible=1;
else
t.Visible=0;
end
pause(0.5)
end
Sadiq Akbar
Sadiq Akbar 2023 年 2 月 1 日
Thanks a lot dear prasanth s for your kind response. It seems good but how can we display the same in command window?

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

採用された回答

DGM
DGM 2023 年 2 月 1 日
移動済み: DGM 2023 年 2 月 1 日
If you want it in the command window, then your options are severely limited, and the rate at which you can "flash" will be limited. Also bear in mind that this blocks the user from doing anything while the text is flashing. Going out of your way to make text flash is an expensive exercise in annoying anyone who ever has to use your code.
Text size and font in the console is defined in preferences. Colors can be configured to some degree if you use cprintf(). It will be laggy and the color will be glitchy. Are there other ways to do this? I don't know. Maybe there is with the new UI. Is it a good idea? I doubt it.
mytext = 'this is a bad design decision';
timeon = 1;
timeoff = 0.5;
numcycles = 10;
for k = 1:numcycles
% print the text
cprintf('red','%s\n',mytext);
pause(timeon)
% delete the text
fprintf('%s',repmat(char(8),[1 numel(mytext)+1]));
pause(timeoff)
end
cprintf('red','%s\n',mytext); % leave the message in place?
If you can settle for losing color, you can do the same with fprintf(), and at least it will be faster.
  3 件のコメント
Sadiq Akbar
Sadiq Akbar 2023 年 2 月 1 日
移動済み: DGM 2023 年 2 月 1 日
I want to accept your answer but there is no "Accept this answer" button.
DGM
DGM 2023 年 2 月 1 日
If it suffices, I split this off into a separate answer.

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2023 年 2 月 1 日
編集済み: John D'Errico 2023 年 2 月 1 日
You can do that, but since disp is not written to accept those extra arguments, it might not work. Wanting code to do what you want is always a valid thing to try, but it rarely works.
You CAN use cprintf though, to do at least some of what you want.
  3 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 1 日
Does the display need to be to the command window, or could it be text drawn in a figure?
If it must be to the command window then are you Livescript?
Sadiq Akbar
Sadiq Akbar 2023 年 2 月 1 日
Thanks a lot dear Walter Roberson for your kind response. It sould be in command window.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by