How do you send your code to the next line while using the disp comand?
2 次查看(过去 30 天)
显示 更早的评论
Hello! I am attempting to use the disp command to output a long sentence. How do I send my code to the next line, so that when I publish my code into a PDF, it doesn't run off the page.
I tried to use the ellipses, but this doesn't seem to work. I also split the sentence in half by using two separate disp commands, but this just makes the sentence look "choppy". I would really like a continuous sentence that naturally moves to the next line.
Here is an example of what my code looks like:
disp(['This is a really really really really really really really really really long sentence with' num2str(numbers) 'also.'])
0 个评论
回答(1 个)
Jason Moore
2015-2-6
Based upon the formatting you want to do I would suggest using sprintf instead of disp with sprintf you can use format specifications to control how the test is coming out.
Example: sprintf('My text on line 1 \nMy text on line2') Results in:
My text on line 1
My text on line2
Also with sprintf there are many other format strings that can help with spacing
If you still want to stick with the disp command you can get the same behavior with the following command
disp(['My text on line 1' char(10) 'My text on line2'])
In this example I am constructing one large string with the ascii value of 10 for a carriage return in between the two sections of text.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!