From: Wen Zhe on
Hey guys!

Great idea to use cell arrays. I actually did use 'genvarname' to assign my csv files to several variables. But your idea of cell arrays stores it as one variable.

So if i were to plot a graph with two columns in my csv files (which are in the cell array 'data'), how would i be able to call it?

Thanks again.

us <us(a)neurol.unizh.ch> wrote in message <40d1eff0-56cc-4db2-b9c9-ba9ffbbc7afd(a)b5g2000vbl.googlegroups.com>...
> On Jul 27, 4:01 pm, "Andy " <myfakeemailaddr...(a)gmail.com> wrote:
> > "Wen Zhe " <wenzhe2...(a)hotmail.com> wrote in message <i2mo1t$a1...(a)fred.mathworks.com>...
> >
> > > Apologies for being unclear. I've re-ran the code and it worked fine. Here's the problem: i have three csv files and i want to import them onto Matlab as three seperate VARIABLES. With the current code, the output would be 'data1', but that would contain the data from the last csv file.
> >
> > > So, is there any way to store my csv files in seperate variables without overwriting any of them? Any help appreciated. Thanks.
> >
> > Perhaps you should consider storing the data in a cell array:
> >
> > csvFiles = dir('*.csv');
> >
> > filename = cell(length(csvFiles),1); % preallocate
> > data = cell(length(csvFiles),1); % preallocate
> >
> > for k = 1:length(csvFiles)
> >   filename{k} = csvFiles(k).name;
> >   data{k} = importdata(filename);
> > end
>
> well...
> either
>
> filename=csvFiles(k).name;
>
> or
>
> data{k}=importdata(filename{k});
>
> :-)
> us