From: Alana on 15 Apr 2010 16:40 If you can't tell, I'm slightly new with Matlab...so try and bear with me. It doesn't matter if each matrix has a name that reflects the *.txt name. I'll just have to manually label each plot so that it reflects the file name that it came from because at some point I'm going to have to show where each data set came from. To get really specific, each *.txt file has 7 columns, and 3690 rows. Say I want to create a matrix that has column 5 from each *txt file populating the matrix, so it would be a 30 column 3690 matrix. How would I do that? From there, I need to manipulate each column into a matrix (45 x 82). Can I store each of these matrices into another matrix? (Is this what you mean by multiple-dimension matrices?)
From: Matt J on 15 Apr 2010 17:01 "Alana " <asmentek(a)fau.edu> wrote in message <hq7tjn$62t$1(a)fred.mathworks.com>... > If you can't tell, I'm slightly new with Matlab...so try and bear with me. > > It doesn't matter if each matrix has a name that reflects the *.txt name. I'll just have to manually label each plot so that it reflects the file name that it came from because at some point I'm going to have to show where each data set came from. > > To get really specific, each *.txt file has 7 columns, and 3690 rows. Say I want to create a matrix that has column 5 from each *txt file populating the matrix, so it would be a 30 column 3690 matrix. How would I do that? > > From there, I need to manipulate each column into a matrix (45 x 82). Can I store each of these matrices into another matrix? (Is this what you mean by multiple-dimension matrices?) =================== I would recommend something like the following, which assumes that your .txt files are delimited by spaces and that your filenames are stored in cell array of strings called FileNames. e.g. FileNames = {'myFile1','myFile2',....'myFile30'}; for ii=1:30 data=dlmread(FileNames{ii},' ','E1..E3690'); %read 5th column of file S(ii).filename=FileNames{ii}; S(ii).matrix=reshape(data,[45,82]); end Now, as TideMan was telling you, you can plot each data set programmatically rather than manually, by looping through the struct array S for ii=1:30 plot(...); %Use S(ii).matrix for the plot title(['This data was from the file called ' S(ii)]) end
From: Matt J on 15 Apr 2010 17:06 "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hq7ur1$rqd$1(a)fred.mathworks.com>... > title(['This data was from the file called ' S(ii)]) ====== That should have read title(['This data was from the file called ' S(ii).filename])
From: TideMan on 15 Apr 2010 17:12 On Apr 16, 8:40 am, "Alana " <asmen...(a)fau.edu> wrote: > If you can't tell, I'm slightly new with Matlab...so try and bear with me.. > > It doesn't matter if each matrix has a name that reflects the *.txt name. I'll just have to manually label each plot so that it reflects the file name that it came from because at some point I'm going to have to show where each data set came from. > > To get really specific, each *.txt file has 7 columns, and 3690 rows. Say I want to create a matrix that has column 5 from each *txt file populating the matrix, so it would be a 30 column 3690 matrix. How would I do that? > > From there, I need to manipulate each column into a matrix (45 x 82). Can I store each of these matrices into another matrix? (Is this what you mean by multiple-dimension matrices?) Because the matrix from each file is the same size, you can store them in a large array with dimensions 3690x7x30. Now, if you want data from,say, the 21st file, you just address it like this: y=data(:,:,21); Then you can reshape it like this: y=reshape(y,45,82,7); or you could reshape the big array: data=reshape(data,45,82,7,30); and access the data from 21st file like this y=data(:,:,:,21); If you have used dir to get the filenames like this: d=dir('pth_to_files\*.txt'); then the name of the 21st file will be in the structure array: d(21).name So you see you don't need to use the file name as the variable name because it will always be available to you.
From: Alana on 15 Apr 2010 20:32 Thanks for the help!
|
Pages: 1 Prev: Stopping & Starting M-files Next: exported *.eps figure is very washed out/faded |