Clear Filters
Clear Filters

Importing multiple csv files, giving them new names and extracting different columns of data to form seperate datastrings

2 views (last 30 days)
I'm new to using Matlab and found out how to inmport data, rename it and substract different columns out of it, but I would like to know how I can properely use the loop tool to be able to extract different columns and name the datastrings for multiple files. Underneath is the code I used for one file just rewritten for all cases. It works with limited number of importing files, however with to many I run out of memory. Can somebody give me tips how to use loops to make sure the .csvfiles are imported automatically and the names of different columns of these files are are automaticaly generated and renamed either?
Thanks for the help, Rianne
Importdir=dir('*.CSV');
M1=Importdir(1).name;
M2=Importdir(2).name;
M3=Importdir(3).name;
M4=Importdir(4).name;
M5=Importdir(5).name;
M6=Importdir(6).name;
M7=Importdir(7).name;
M1=csvimport (M1);
M1_S3D_S1_D=M1(:,3);
M1_S3D_S1_UV=M1(:,4);
M1_S3D_S1_VV=M1(:,5);
M1_S3D_S1_WV=M1(:,6);
M2=csvimport (M2);
M2_S3D_S1_D=M1(:,3);
M2_S3D_S1_UV=M2(:,4);
M2_S3D_S1_VV=M2(:,5);
M2_S3D_S1_WV=M2(:,6);
%and so on

Accepted Answer

Iain
Iain on 28 Aug 2013
Importdir=dir('*.CSV')
for i = 1:numel(Importdir);
M = Importdir(i).name;
M =csvimport (M);
M_D{i} = M(:,3);
M_U{i} = M(:,4);
M_V{i} = M(:,5);
M_W{i} = M(:,6);
end
If you have too many files, you'll still run out of memory...

More Answers (0)

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!