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:
importing data in file with a numerical prefix in a for loop

Subject: importing data in file with a numerical prefix in a for loop

From: Chatu

Date: 10 Dec, 2012 05:34:12

Message: 1 of 3

Hi

I am very new to MATLAB, so I am fairly certain that this is a very simple question. I have several output data sets, each with a prefix (e.g. WQ_50 to WQ_83). I would like to use a for loop to import data from the first column (having temperature data) of each of the output data set to a new matrix.

files = 50:1:83
for i = 1:length(files);
    dataN = importdata ('WQ_(files(i)).csv');
    tempN (i,:) = dataN.data (:,1);
end

but i keep getting a message saying error in importdata

Any help would be great

Subject: importing data in file with a numerical prefix in a for loop

From: Bruno Luong

Date: 10 Dec, 2012 07:25:14

Message: 2 of 3

"Chatu " <chatu.wick@hotmail.com> wrote in message <ka3s8k$1vv$1@newscl01ah.mathworks.com>...
> Hi
>
> I am very new to MATLAB, so I am fairly certain that this is a very simple question. I have several output data sets, each with a prefix (e.g. WQ_50 to WQ_83). I would like to use a for loop to import data from the first column (having temperature data) of each of the output data set to a new matrix.
>
> files = 50:1:83
> for i = 1:length(files);
> dataN = importdata ('WQ_(files(i)).csv');
> tempN (i,:) = dataN.data (:,1);
> end
>
> but i keep getting a message saying error in importdata
>
> Any help would be great

To build the filenames, replace 'WQ_(files(i)).csv' with sprintf('WQ_(%d).csv', file(i))

% Bruno

Subject: importing data in file with a numerical prefix in a for loop

From: Chatu

Date: 12 Dec, 2012 06:24:09

Message: 3 of 3

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ka42oq$m7l$1@newscl01ah.mathworks.com>...
> "Chatu " <chatu.wick@hotmail.com> wrote in message <ka3s8k$1vv$1@newscl01ah.mathworks.com>...
> > Hi
> >
> > I am very new to MATLAB, so I am fairly certain that this is a very simple question. I have several output data sets, each with a prefix (e.g. WQ_50 to WQ_83). I would like to use a for loop to import data from the first column (having temperature data) of each of the output data set to a new matrix.
> >
> > files = 50:1:83
> > for i = 1:length(files);
> > dataN = importdata ('WQ_(files(i)).csv');
> > tempN (i,:) = dataN.data (:,1);
> > end
> >
> > but i keep getting a message saying error in importdata
> >
> > Any help would be great
>
> To build the filenames, replace 'WQ_(files(i)).csv' with sprintf('WQ_(%d).csv', file(i))
>
> % Bruno

Thanks so much.

Now I can see that it recognises the file names correctly but it doesn't really do what I want it to do, as it over writes the data with each loop. Obviously, I have the coding wrong. What I basically require is to have the first column of the each of the csv file imported and formed into a single matrix.

Can anyone kindly help me with figuring out hhow to write a suitable code for that?

Thanks!

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