Prev: call a UNIX function from an .m file
Next: SSMCMA
From: Paul on 19 Jul 2010 17:37 Hello, I have been having an issue working with multiple data files in a loop. I have several data files... input001 input002 input003 ... which I have loaded by files=dir('input*') for i=1:length(files) eval(['load ' files(i).name]); At this point (inside the loop), I want to make a vector out of column #1 in files(1), but when I attempt this line... x=files(1).name(:,1) it assings the string 'i' to x, instead of a data column. Can anyone help? Am I missing a simple tag? Thanks so much!
From: Steven_Lord on 19 Jul 2010 17:43 "Paul " <palex71(a)hotmail.com> wrote in message news:i22gi0$cdq$1(a)fred.mathworks.com... > Hello, > I have been having an issue working with multiple data files in a loop. > I have several data files... > input001 > input002 > input003 ... > > which I have loaded by > > files=dir('input*') > for i=1:length(files) > eval(['load ' files(i).name]); NO. DO NOT DO THIS. Instead, call LOAD with an output argument: data = load(files(i).name); Then you can index into data however you want. > At this point (inside the loop), I want to make a vector out of column #1 > in files(1), but when I attempt this line... > > x=files(1).name(:,1) > > it assings the string 'i' to x, instead of a data column. That is the correct behavior. files(1).name is 'input001' and the first column of that char array is the character 'i'. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: per isakson on 19 Jul 2010 17:52 "Paul " <palex71(a)hotmail.com> wrote in message <i22gi0$cdq$1(a)fred.mathworks.com>... > Hello, > I have been having an issue working with multiple data files in a loop. > I have several data files... > input001 > input002 > input003 ... > > which I have loaded by > > files=dir('input*') > for i=1:length(files) > eval(['load ' files(i).name]); > > At this point (inside the loop), I want to make a vector out of column #1 in files(1), but when I attempt this line... > > x=files(1).name(:,1) > > it assings the string 'i' to x, instead of a data column. > > Can anyone help? Am I missing a simple tag? > > Thanks so much! files(1).name is the name of the file and files(1).name(:,1) is the first character of the name of the file, i.e. "i". Read the documentation of load, which recommend against using this syntax when the filename is the value of a variable. What's in the files? / per
From: Paul on 20 Jul 2010 13:51 Thanks, guys... it is working. :)
|
Pages: 1 Prev: call a UNIX function from an .m file Next: SSMCMA |