Reading only certain columns from .csv file in matlab

13 ビュー (過去 30 日間)
Prasanna Venkatesh
Prasanna Venkatesh 2018 年 6 月 28 日
回答済み: dpb 2018 年 6 月 28 日
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

回答 (1 件)

dpb
dpb 2018 年 6 月 28 日
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
...

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by