MATLAB How to Display Values in MATLAB Using disp and sprintf with Named Columns?

  • Thread starter Thread starter tigertan
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
To display values in MATLAB using disp and sprintf with named columns, the user can utilize sprintf to format the output. The values Z = 23, -12, -31, -20, -23, -13.8 can be aligned by separating column headers A1, A2, A3, S4, S5, S6 with tabs using the escape character \t. It is important to consider the number of tabs based on the number of digits in the values for proper alignment. Clarification is needed on whether the output is intended for the command window or a text file. Proper formatting will enhance readability in the output display.
tigertan
Messages
24
Reaction score
0
How can I display my values:

Z = 23 -12 -31 -20 -23 -13.8

using disp and sprintf and naming the columns A1, A2, A3, S4, S5, S6 respectively (in Matlab)?

I hope you can help! am desperate
 
Physics news on Phys.org
MatLab doesn't come with printf, but it does have sprintf, so to output formated text to the console, you may do this.

Code:
disp(sprintf("hello world"));

You may read about sprintf at http://www.mathworks.com/help/techdoc/ref/sprintf.html.

To align the Columns, you may separate the column headers by one or more tabs. This is the escape character for tab:

Code:
\t

if you are printing numbers with more digits, the column headers may have to be separated with more tabs than the tabs between numbers on a row.
 
Last edited:
Hi MisterX

Thank you kindly for your response!

Yes I did in fact mean using the function disp(sprintf(...

I have no idea how I'd go about setting it up though??

I have defined my Z values already. How can I input that directly?
 
Did you read the "Examples" section through the link in my previous post?
 
I'm not sure what you're trying to do... can you type out or post an image of what you'd like the output to actually look like?

Also, are you writing this to a text file or to the command window?
 

Similar threads

Replies
9
Views
5K
Replies
6
Views
2K
Replies
1
Views
2K
Replies
11
Views
3K
Replies
2
Views
3K
Replies
1
Views
2K
Back
Top