|
"Miroslav Balda" <balda.nospam@cdm.it.cas.cz> wrote in
message <g2kvft$lnc$1@fred.mathworks.com>...
> "Hydroman S" <amirgsalem@gmail.com> wrote in message
> <g2k9td$83t$1@fred.mathworks.com>...
> > If I have a matrix
> >
> > a=magic(4)
> >
> > 16 2 3 13
> > 5 11 10 8
> > 9 7 6 12
> > 4 14 15 1
> >
> > Is it possible to write the matrix data to a *.txt
file
> > such that it would look like this:
> >
> > 60
> > 16 2 3 13
> > 5 11 10 8
> > 9 7 6 12
> > 4 14 15 1
> > carret return
> >
> > basically, I need to add the number 60 on top of
column 1,
> > and a "carret return" after column 1?
> >
>
> Hi
> Your note on 'column 1' is not very clear, nevertheless,
if
> the result should look like you presented, the code can
be
>
> fid = fopen('test.txt','w');
> fprintf(fid,'%2d\n',60);
> fprintf(fid,'%3d %3d %3d %3d \n', a');
> fprintf(fid,'%s',char(13));
> fclose(fid);
>
> Mira
>
Thank you Mira, this works, but what if "a" is not a
square matrix, i.e a=rand(3,2); I end up with an extra
value at the end of column 1. Can you recommed a decent
ref. on how to use fprintf?
|