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
Click For Summary

Discussion Overview

The discussion revolves around how to display values in MATLAB using the functions disp and sprintf, specifically focusing on naming columns for a set of values. The context includes technical explanations and practical applications related to MATLAB programming.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant asks how to display a set of values using disp and sprintf while naming the columns A1, A2, A3, S4, S5, S6.
  • Another participant clarifies that MATLAB uses sprintf for formatted output and suggests using tabs to align column headers.
  • A participant expresses confusion about how to set up the display function with their defined values.
  • One participant prompts for clarification on the desired output format and whether the output is intended for a text file or the command window.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the exact method to achieve the desired output, and multiple viewpoints regarding the setup and formatting remain present.

Contextual Notes

There are limitations regarding the clarity of the desired output format and the specific setup for using disp and sprintf together, which may depend on the participant's familiarity with MATLAB.

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 ·
Replies
9
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 2 ·
Replies
2
Views
6K