フィルターのクリア

How do I create a new line after a loop function gives output

15 ビュー (過去 30 日間)
Hank Gunderson
Hank Gunderson 2021 年 12 月 23 日
コメント済み: Hank Gunderson 2021 年 12 月 23 日
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
I want it to output the prompt on a new line but when I try newline or sprintf('\r') it types text
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
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.
Hank Gunderson
Hank Gunderson 2021 年 12 月 23 日
編集済み: Hank Gunderson 2021 年 12 月 23 日
if true
clear
w0=0;%start weight
w1=0;%end weight
n=0; %number of cutters
wc=0; %cut weight
wd=0; % scale weight of 2 units
z=0; % number of rings (30s)
cuts=0;
n=6;
m=0;
z=input('enter number of 30s');
while(m<z)
w0=input('enter start weight'); w1=input('enter end weight'); wd=2.2; wc=.5*wd*(1/16)*n; cuts=32*(w0-w1)/(n*wd); clc fprintf('estimated cuts: %3.0f',cuts) m=m+1;
sprintf('\r');
end % code
end
Answer this question
Answers (1)
Star Strider
42 minutes ago
 ⋮ 
Accept this answer Ran in: Without seeing the rest of the code — Theme
Theme
estimatedCuts = randi(999); fprintf('estimated cuts: %d \n', estimatedCuts) estimated cuts: 441 fprintf('next line') next line in the fprintf documentation under formatSpec scroll down to see Text Before or After Formatting Operators (there is no direct link to it). .    0 Comments
Answer this question
See Also
MATLAB Answers
how do i create a vector from user inputs? this is what i have so far but it does not work.
1 Answer
Recording a sound and inserting to a matrix as a new column
0 Answers
how can i identify the given jpeg image uses same quantization matrix or different quantization matrix?
0 Answers Entire Website
Two Dimensional Frame FE Solver
File Exchange
Two Dimensional Truss FE Solver
File Exchange
JPEG Compression
File Exchange
Tags Add/Edit
loops newline while loop output
Products Add/Edit
MATLAB
Release
Add/Edit
R2019a
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Perform Hardware-in-the-Loop Simulation with MATLAB and Simulink
Read white paper
Trial software MathWorks
Accelerating the pace of engineering and science
MathWorks is the leading developer of mathematical computing software for engineers and scientists.
Discover…
Explore Products
Try or Buy
Learn to Use
Get Support
About MathWorks
Select a Web SiteUnited States Trust Center Trademarks Privacy Policy Preventing Piracy Application Status Terms of Use © 1994-2021 The MathWorks, Inc.
Join the conversation

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

採用された回答

Image Analyst
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 ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by