How do I create a new line after a loop function gives output
15 ビュー (過去 30 日間)
古いコメントを表示
I have a loop that makes the same calculation multiple times based on my input. But when it gives me the output (some number) it immediately types the input prompt immediately after the number
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/841770/8702FE76-3BC5-4588-B21E-BC77A1E3750F.jpeg)
I want it to output the prompt on a new line but when I try newline or sprintf('\r') it types text
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/841775/ACE11AAA-AC0F-4FE9-882A-7EDB2CD556D4.jpeg)
How do I make it start the prompt from each run through the loop start on a new line without it typing a bunch of extra text? I tried using a “;” after but that changes it back to the first picture
2 件のコメント
Voss
2021 年 12 月 23 日
Can you share the actual code you are using? At least the call to input() and the relevant parts of the loop. I'm unable to reproduce the behavior you describe.
採用された回答
Image Analyst
2021 年 12 月 23 日
Don't use sprintf() like you did. Use fprintf() instead
fprintf('\n'); % Print blank line to command window.
Using sprintf() without accepting the output of sprintf() into a variable will put it into the default variable "ans" and if you left off the semicolon, it will echo that to the command window like you're seeing. If you do accept it into a variable, it will just put it into the variable and not do anything at all with the command window. That's why you need to use fprintf('\n') instead, because that will put out a blank line to the command window, scrolling all prior output upwards.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!