From: Tarakapraveen on
Hi,

Is there any flexible way of using "fprintf" in matlab to print a vector in multi columns.

e.g.
DataVec = [1+2j,3+4j,2+3j,5+2j];
fprintf('%f %f\n', real(DataVec), imag(DataVec));

Output :
1.0 3.0
2.0 5.0
2.0 4.0
3.0 2.0

Expected Output :
1.0 2.0
3.0 4.0
2.0 3.0
5.0 2.0

Even there is work around (by interleaving data) to get this expected output but it costs memory.

Thanks,
Tarakapraveen

From: Nandish on
"Tarakapraveen " <tarakapraveen(a)yahoo.com> wrote in message <hu7ssk$sd8$1(a)fred.mathworks.com>...
> Hi,
>
> Is there any flexible way of using "fprintf" in matlab to print a vector in multi columns.
>
> e.g.
> DataVec = [1+2j,3+4j,2+3j,5+2j];
> fprintf('%f %f\n', real(DataVec), imag(DataVec));
>
> Output :
> 1.0 3.0
> 2.0 5.0
> 2.0 4.0
> 3.0 2.0
>
> Expected Output :
> 1.0 2.0
> 3.0 4.0
> 2.0 3.0
> 5.0 2.0
>
> Even there is work around (by interleaving data) to get this expected output but it costs memory.
>
> Thanks,
> Tarakapraveen
>
Hey Tarakapraveen

try this one...

for i= 1:4
fprintf('%f %f\n', real(DataVec(i)), imag(DataVec(i)));
end

hope this will help.

Nandish
From: Tarakapraveen on
"Nandish " <nandishpatel.24(a)gmail.com> wrote in message <hu7u7n$rc0$1(a)fred.mathworks.com>...
> "Tarakapraveen " <tarakapraveen(a)yahoo.com> wrote in message <hu7ssk$sd8$1(a)fred.mathworks.com>...
> > Hi,
> >
> > Is there any flexible way of using "fprintf" in matlab to print a vector in multi columns.
> >
> > e.g.
> > DataVec = [1+2j,3+4j,2+3j,5+2j];
> > fprintf('%f %f\n', real(DataVec), imag(DataVec));
> >
> > Output :
> > 1.0 3.0
> > 2.0 5.0
> > 2.0 4.0
> > 3.0 2.0
> >
> > Expected Output :
> > 1.0 2.0
> > 3.0 4.0
> > 2.0 3.0
> > 5.0 2.0
> >
> > Even there is work around (by interleaving data) to get this expected output but it costs memory.
> >
> > Thanks,
> > Tarakapraveen
> >
> Hey Tarakapraveen
>
> try this one...
>
> for i= 1:4
> fprintf('%f %f\n', real(DataVec(i)), imag(DataVec(i)));
> end
>
> hope this will help.
>
> Nandish

Thanks for the reply Nandish.
Even though there are ways but i am looking for single statement printing without any loops (since when we go for printing huge data, for loop kills the speed).

The following statement should work for any length.

fprintf('%f %f\n', real(DataVec(:)), imag(DataVec(:)));

Thanks,
Tarakapraveen
From: Walter Roberson on
Tarakapraveen wrote:

> Is there any flexible way of using "fprintf" in matlab to print a vector
> in multi columns.

No.


> e.g. DataVec = [1+2j,3+4j,2+3j,5+2j];
> fprintf('%f %f\n', real(DataVec), imag(DataVec));

> Even there is work around (by interleaving data) to get this expected
> output but it costs memory.

Everything costs memory in Matlab -- even just transposing a matrix
costs memory (unless the matrix was a vector.)
From: Jan Simon on
Dear Tarakapraveen!

> The following statement should work for any length.
> fprintf('%f %f\n', real(DataVec(:)), imag(DataVec(:)));

fprintf('%f %f\n', transpose([real(DataVec(:)), imag(DataVec(:))]))
or if DataVec is a row vector:
fprintf('%f %f\n', [real(DataVec); imag(DataVec)])

Kind regards, Jan
 |  Next  |  Last
Pages: 1 2
Prev: mask in subsystem block
Next: to read a raw file