Reading only certain columns from .csv file in matlab
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
dpb
el 28 de Jun. de 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 comentarios
Ver también
Categorías
Más información sobre Workspace Variables and MAT Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!