Reading only certain columns from .csv file in matlab
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have multiple csv files that have 500 rows and 1000 columns with each column having a variable name. I want to read in only data from 10 variable names out of the 1000 and store it in a seperate csv file which should then have 500 rows and 10 columns.
M=csvread('filename', 0,0);
reads in the entire file but how do I get to select only the 10 columns i need?
Thanks
0 Kommentare
Antworten (1)
dpb
am 28 Jun. 2018
It's far simpler to read the whole file into memory and then just cull the ones not wanted or keep those that are...and probably faster as well altho these files are small enough that time won't be an issue either way.
idxKeep=[randperm(1000,10)]; % arbitrary 10 elements to keep out of 1000 for illustration
M=csvread('filename');
M=M(:,idxKeep); % save only those desired columns
% do whatever with these data now
...
0 Kommentare
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!