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:
How to write multiple files (.dat or .txt) with consecutive file names in matlab

Subject: How to write multiple files (.dat or .txt) with consecutive file names in matlab

From: Kris

Date: 11 Mar, 2013 03:41:09

Message: 1 of 3

I have the following scenario:

for t = 1:10 % As time goes from 1 to 10.

           for i = 1:10 % As position goes from 1 to 10.

                 u(i) = some operation

           end


s = u'; % Just getting a transpose so i can read the data better.

save ("File(i).txt', 's', '-ascii', '-tabs');
                                             
                                       % I know this doesn't work. I need a help with this.

end

Desired output:

File1 : with data at t = 1 and i = 1:10.
File 2: with data at t=2 and i = 1:10;
and so on.


How to save multiple files using a for loop, or any other method would would also work.

Subject: How to write multiple files (.dat or .txt) with consecutive file

From: TideMan

Date: 11 Mar, 2013 08:32:57

Message: 2 of 3

On Monday, March 11, 2013 4:41:09 PM UTC+13, Kris wrote:
> I have the following scenario:
>
>
>
> for t = 1:10 % As time goes from 1 to 10.
>
>
>
> for i = 1:10 % As position goes from 1 to 10.
>
>
>
> u(i) = some operation
>
>
>
> end
>
>
>
>
>
> s = u'; % Just getting a transpose so i can read the data better.
>
>
>
> save ("File(i).txt', 's', '-ascii', '-tabs');
>
>
>
> % I know this doesn't work. I need a help with this.
>
>
>
> end
>
>
>
> Desired output:
>
>
>
> File1 : with data at t = 1 and i = 1:10.
>
> File 2: with data at t=2 and i = 1:10;
>
> and so on.
>
>
>
>
>
> How to save multiple files using a for loop, or any other method would would also work.

You're almost there.........
txtfile=['File' num2str(i) '.txt']; % Need to convert index to string
save (txtfile, 's', '-ascii', '-tabs');

Subject: How to write multiple files (.dat or .txt) with consecutive file

From: Ryan

Date: 12 Mar, 2013 03:32:11

Message: 3 of 3

Take a look at this (I just found it today):
http://matlab.wikia.com/wiki/FAQ

Hit Ctrl+F, and search for this: 'How can I process a sequence of files?'

TideMan <mulgor@gmail.com> wrote in message <44c42b47-eff8-44f0-97b5-717ee6e5541f@googlegroups.com>...
> On Monday, March 11, 2013 4:41:09 PM UTC+13, Kris wrote:
> > I have the following scenario:
> >
> >
> >
> > for t = 1:10 % As time goes from 1 to 10.
> >
> >
> >
> > for i = 1:10 % As position goes from 1 to 10.
> >
> >
> >
> > u(i) = some operation
> >
> >
> >
> > end
> >
> >
> >
> >
> >
> > s = u'; % Just getting a transpose so i can read the data better.
> >
> >
> >
> > save ("File(i).txt', 's', '-ascii', '-tabs');
> >
> >
> >
> > % I know this doesn't work. I need a help with this.
> >
> >
> >
> > end
> >
> >
> >
> > Desired output:
> >
> >
> >
> > File1 : with data at t = 1 and i = 1:10.
> >
> > File 2: with data at t=2 and i = 1:10;
> >
> > and so on.
> >
> >
> >
> >
> >
> > How to save multiple files using a for loop, or any other method would would also work.
>
> You're almost there.........
> txtfile=['File' num2str(i) '.txt']; % Need to convert index to string
> save (txtfile, 's', '-ascii', '-tabs');

Tags for this Thread

No tags are associated with 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