Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



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


<mailcwc@gmail.com> wrote in message news:445657a1ca374e6082bf22f56cdd00b4@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, ND arrays, etc.) to taste.
 Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com



