Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
writing file

Subject: writing file

From: Jonathan

Date: 1 Jun, 2011 03:33:04

Message: 1 of 4

G'day,
I have a matrix (n,3). I am trying to write the data to a file. However, the format of the final file is very specific of the form:

    4.59 120.00 1.0
    3.57 110.00 5.0
    5.61 130.00 4.0
    5.61 120.00 3.0

It's not clear to me how I can write such a file in Matlab. I have played around with dlmwrite but can't get it to match exactly the above format. Is there another way to do this?

Thanks
Jon

Subject: writing file

From: Kirill

Date: 1 Jun, 2011 03:56:23

Message: 2 of 4

On May 31, 11:33 pm, "Jonathan" <jkak...@yahoo.co.uk> wrote:
> G'day,
> I have a matrix (n,3).  I am trying to write the data to a file.  However, the format of the final file is very specific of the form:
>
>     4.59  120.00     1.0
>     3.57  110.00     5.0
>     5.61  130.00     4.0
>     5.61  120.00     3.0
>
> It's not clear to me how I can write such a file in Matlab.  I have played around with dlmwrite but can't get it to match exactly the above format. Is there another way to do this?
>
> Thanks
> Jon

fprintf()

Subject: writing file

From: vedenev

Date: 1 Jun, 2011 04:06:14

Message: 3 of 4

another way: save command, example:
A=[1 2 3; 4 5 6];
save('A.txt','A','-ascii');

how result looks:
  1.0000000e+000 2.0000000e+000 3.0000000e+000
  4.0000000e+000 5.0000000e+000 6.0000000e+000

------------------------------------
Maxim Vedenev, Matlab coder
vedenev@ngs.ru
http://simulations.narod.ru/

Subject: writing file

From: Jonathan

Date: 1 Jun, 2011 04:54:02

Message: 4 of 4

Kirill <kirillandreev@gmail.com> wrote in message <1ba53e31-ef7b-4459-9143-64cbb551906e@em7g2000vbb.googlegroups.com>...
> On May 31, 11:33 pm, "Jonathan" <jkak...@yahoo.co.uk> wrote:
> > G'day,
> > I have a matrix (n,3).  I am trying to write the data to a file.  However, the format of the final file is very specific of the form:
> >
> >     4.59  120.00     1.0
> >     3.57  110.00     5.0
> >     5.61  130.00     4.0
> >     5.61  120.00     3.0
> >
> > It's not clear to me how I can write such a file in Matlab.  I have played around with dlmwrite but can't get it to match exactly the above format. Is there another way to do this?
> >
> > Thanks
> > Jon
>
> fprintf()

Thanks Kirill. This worked!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us