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

  • Context: MATLAB 
  • Thread starter Thread starter tigertan
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 6K views
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?