フィルターのクリア

how to display newline

703 ビュー (過去 30 日間)
Tor Fredrik Hove
Tor Fredrik Hove 2011 年 10 月 16 日
回答済み: Steven Lord 2022 年 9 月 6 日
Can you use newline seperately or do you always have to use it in fprintf in order to make it work. Theese are my attempts with newline:
this did not work:
This gave a strange result
Is this the only way to make a newline?:
Here is my script for the last line:
rows=3;
columns=5;
for i=1:rows
for j=1:columns
fprintf('*')
end
fprintf('\n')
end
  1 件のコメント
the cyclist
the cyclist 2011 年 10 月 16 日
I think you got the answer you need from Wayne, but for future reference, you posted three copies of the same image in this question.

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

採用された回答

Wayne King
Wayne King 2011 年 10 月 16 日
Hi, '\n' by itself outside of special calls is just interpreted as the string (character array) \n
It's not just in fprintf(), sprintf() also interprets escape characters correctly like \n or \t
but yes you're right:
disp('Hi \n nice to meet you')
% produces Hi \n nice to meet you
but
fprintf('Hi \n nice to meet you')
% Hi
% nice to meet you>>
  4 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 19 日
disp(sprintf('Hi \n nice to meet you'))
Sina Davari
Sina Davari 2020 年 12 月 11 日
Hi;
You could simply put { disp(' '); } between two disp for obtaining an empty line.
disp('Hi'); disp(' '); disp('nice to meet you')

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

その他の回答 (3 件)

Steven Lord
Steven Lord 2022 年 9 月 6 日
If you're using release R2016b or later you can use the newline function, perhaps in conjunction with a string array.
s = "apple" + newline + "banana"
s =
"apple banana"
c = ['apple', newline, 'banana']
c =
'apple banana'

Kleber Zuza Nobrega
Kleber Zuza Nobrega 2020 年 9 月 19 日
supose you want to disp the word 'Ball'. Try
a=['Ball',char(13),'to a new line']
disp(a)
  4 件のコメント
Walter Roberson
Walter Roberson 2020 年 11 月 15 日
Or
disp("Ball" + newline + "to a new line");
Daniel Gonzalez
Daniel Gonzalez 2021 年 8 月 25 日
char(10) worked for me, but great advice.

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


Saul Stokar
Saul Stokar 2022 年 9 月 6 日
Youj can do it using sprintf :
string2Print=sprintf('%s\n','Hi','nice to meet you');
disp(string2Print)
This prints:
Hi
nice to meet you

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by