From: Steven Lord on

"Mark Shore" <mshore(a)magmageosciences.ca> wrote in message
news:hpkjfp$i8l$1(a)fred.mathworks.com...
> "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.

Keep in mind that FPRINTF can write to the command window as well as a file.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fprintf.html

"fprintf(format, A, ...) formats data and displays the results on the
screen."

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: TC Christensen on
Thank you for all your (very) fast responses.

It's unfortunate if it's really the case that format 'short', 'long' etc are really the only options for the output in the command window.

I've tried to use fprintf as you adviced, by use of the following bit of code (where my many-digited matrix is contained in A):
____________
for jj = 1:size(A,1)
fprintf('%3.0f ',e2e1M(jj,:));
fprintf('\n');
end
____________
This works OK, but my matrix A contains elements that are either real nonzero elements, zero elements or purely imaginary elements. The imaginary elements are not printed when using this approach - Any suggestions to circumvent this problem would be greatly appreciated.

PS. I've tagged the other thread with duplicate post now - Thanks for the tip.
From: Walter Roberson on
TC Christensen wrote:

> for jj = 1:size(A,1)
> fprintf('%3.0f ',e2e1M(jj,:));
> fprintf('\n');
> end

> This works OK, but my matrix A contains elements that are either real
> nonzero elements, zero elements or purely imaginary elements. The
> imaginary elements are not printed when using this approach - Any
> suggestions to circumvent this problem would be greatly appreciated.

Unfortunately Matlab does not have a format specifier for outputting
complex values, so you have to do it yourself.

You have the choice of either outputting everything as complex (simpler
coding, vectorizable), or of only outputting the complex portion when it
is non-zero (slower, not as easily vectorizable, but more compact.)

I may be getting your situation confused with someone else's, but
weren't you constrained by the representation expected by an external
program?
From: TC Christensen on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hpnj07$kdv$1(a)canopus.cc.umanitoba.ca>...
> TC Christensen wrote:
>
> > for jj = 1:size(A,1)
> > fprintf('%3.0f ',e2e1M(jj,:));
> > fprintf('\n');
> > end
>
> > This works OK, but my matrix A contains elements that are either real
> > nonzero elements, zero elements or purely imaginary elements. The
> > imaginary elements are not printed when using this approach - Any
> > suggestions to circumvent this problem would be greatly appreciated.
>
> Unfortunately Matlab does not have a format specifier for outputting
> complex values, so you have to do it yourself.
>
> You have the choice of either outputting everything as complex (simpler
> coding, vectorizable), or of only outputting the complex portion when it
> is non-zero (slower, not as easily vectorizable, but more compact.)
>
> I may be getting your situation confused with someone else's, but
> weren't you constrained by the representation expected by an external
> program?

Hm, I think you must have me confused with someone else, but no worries.

The last option you mention, the "outputting the complex portion when it
> is non-zero (slower, not as easily vectorizable, but more compact.)" - how do I use this option in practice?

Thank you.