Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB disp sprintf question

  1. Dec 5, 2011 #1
    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
  2. jcsd
  3. Dec 5, 2011 #2
    MatLab doesn't come with printf, but it does have sprintf, so to output formated text to the console, you may do this.

    Code (Text):

    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 seperate the column headers by one or more tabs. This is the escape character for tab:

    Code (Text):
    if you are printing numbers with more digits, the column headers may have to be seperated with more tabs than the tabs between numbers on a row.
    Last edited: Dec 5, 2011
  4. Dec 5, 2011 #3
    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?
  5. Dec 5, 2011 #4
    Did you read the "Examples" section through the link in my previous post?
  6. Dec 5, 2011 #5
    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?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook