フィルターのクリア

adding a space or two after the output

97 ビュー (過去 30 日間)
Tri
Tri 2014 年 7 月 10 日
編集済み: Cody Brant Watson 2018 年 9 月 7 日
how do I add a space after my output using disp()?

採用された回答

Image Analyst
Image Analyst 2014 年 7 月 10 日
Try
>> format loose

その他の回答 (4 件)

Ben11
Ben11 2014 年 7 月 10 日
I don't think you can with "disp"; or at least I don't see how to check it. An alternative would be to use sprintf:
A = sprintf('hello');
B = sprintf('hello '); % added 2 space characters at the end
whos
Name Size Bytes Class Attributes
A 1x5 10 char
B 1x7 14 char
So B does contain 2 more characters than A, i.e. the spaces at the end. Is that what you meant? If not please add details.

Schwank
Schwank 2018 年 3 月 5 日
I was having the same issue with this answering a homework question. I was inputting a first and a last name, using disp() as my output. f=input(first name) l=input(last name) disp(['Your name is: ',f,' ',l]). The key is putting the ' ' in between the f and l inputs for the array.
  2 件のコメント
Image Analyst
Image Analyst 2018 年 3 月 6 日
That puts a space between the strings on the same line. What the poster has now is when "my output shows up, the EDU>> is the very next line" and what the poster said he wants is "I just wanted there to be a couple of blank spaces" between the string and the EDU>> prompt.
In other words, if the string was 'Hello World' and the program was
str = 'Hello World';
disp(str)
instead of the normal
Hello World
EDU>>
tri (the poster) wants to see this:
Hello World
EDU>>
where there are two blank lines after the display of the string value and the next command line prompt.
Cody Brant Watson
Cody Brant Watson 2018 年 9 月 7 日
編集済み: Cody Brant Watson 2018 年 9 月 7 日
disp(' ') % There is a space between the single quotes.

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


Tri
Tri 2014 年 7 月 10 日
Thank you....I meant when my output shows up, the EDU>> is the very next line and I just wanted there to be a couple of blank spaces. Hopefully that clarifies. Thanks again

Tri
Tri 2014 年 7 月 10 日
Thank you, will give it a try.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by