Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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: 17,944
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



<mailcwc@gmail.com> wrote in message
news:445657a1-ca37-4e60-82bf-22f56cdd00b4@h3g2000yqa.googlegroups.com...
> 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;
showOneLine(a)

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

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.