The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How do I show variable value in the same line of variable name in the
command window

Replies: 1   Last Post: Nov 30, 2011 9:36 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: How do I show variable value in the same line of variable name in the command window
Posted: Nov 30, 2011 9:36 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

<> wrote in message
> I want to list the values of some selected variables in a given order.
> The most easy way is type each variable one by one.
> For examples,
> a=1;
> b=2;
> c=3;
> a
> b
> c
> In the command widows, it will show
> a =
> 1
> b =
> 2
> c =
> 3
> Is it possible to make it look like
> a = 1
> b = 2
> c = 3
> I don't want the values showed in a new line.
> the later is more readable for me.

If you object to the blank lines between the variables being displayed, then
FORMAT COMPACT may be sufficient for your needs. If it isn't, doing this
exactly as your code shows would not be possible without overloading how the
display function works in general, which is a rather big hammer. If you are
okay with calling a function to display your variables in this manner, it's
much easier.

function showOneLine(variable)
nameOfVariable = inputname(1);
fprintf('%s = %s\n', nameOfVariable, mat2str(variable));

a = 1;

Add error checking (empty nameOfVariable, N-D arrays, etc.) to taste.

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.