From: TC Christensen on
Hi,

I am looking for a way to _precisely_ define the number of output decimals in the MATLAB command window. I know and am familiar with the 'format' command - however, I can only force it to either give me 4 digits (short) or 15 (long).

In this specific case, I want the output (which is a 50*50 matrix) to be shown with zero decimals. Is this possible to do? And is there a general way to set the number of decimals to exactly the number I want?

I look forward to reading your suggestions. Best regards,
Thomas
From: TC Christensen on
I appologuize for posting the same post twice - maybe an admit could remove this post for me, so that the discussion can be centered in the other post. Again, sorry.
From: Mark Shore on
"TC Christensen" <thomastc32(a)gmail.com> wrote in message <hpkhvk$op4$1(a)fred.mathworks.com>...
> Hi,
>
> I am looking for a way to _precisely_ define the number of output decimals in the MATLAB command window. I know and am familiar with the 'format' command - however, I can only force it to either give me 4 digits (short) or 15 (long).
>
> In this specific case, I want the output (which is a 50*50 matrix) to be shown with zero decimals. Is this possible to do? And is there a general way to set the number of decimals to exactly the number I want?
>
> I look forward to reading your suggestions. Best regards,
> Thomas

My understanding (which may be wrong) is that the command window allows one or the other (long or short) with no other options. Writing to files (fprintf, fwrite, dlmwrite) is far more flexible.

It's easy to tag your other post with "duplicate post" to focus answers on just one thread.
From: Sean on
"TC Christensen" <thomastc32(a)gmail.com> wrote in message <hpkhvk$op4$1(a)fred.mathworks.com>...
> Hi,
>
> I am looking for a way to _precisely_ define the number of output decimals in the MATLAB command window. I know and am familiar with the 'format' command - however, I can only force it to either give me 4 digits (short) or 15 (long).
>
> In this specific case, I want the output (which is a 50*50 matrix) to be shown with zero decimals. Is this possible to do? And is there a general way to set the number of decimals to exactly the number I want?
>
> I look forward to reading your suggestions. Best regards,
> Thomas

For this case you could do.
>>round(matrix)
From: Walter Roberson on
TC Christensen wrote:

> I am looking for a way to _precisely_ define the number of output
> decimals in the MATLAB command window. I know and am familiar with the
> 'format' command - however, I can only force it to either give me 4
> digits (short) or 15 (long).

> In this specific case, I want the output (which is a 50*50 matrix) to be
> shown with zero decimals. Is this possible to do? And is there a general
> way to set the number of decimals to exactly the number I want?

The general way is to use sprintf() or fprintf() to format the numbers
into strings and then to display the strings.

The matlab 'format' command is relatively inflexible.


There are also some tricks that can be done by overriding the display()
routine, but I would not recommend even _considering_ that route to
anyone who was not fairly familiar with sprintf .


By the way: have you considered outputting round() or fix() or ceil() of
the array instead of the array itself?