Reading data from csv files

2 ビュー (過去 30 日間)
Ahmad Hasnain
Ahmad Hasnain 2019 年 4 月 23 日
回答済み: Guillaume 2019 年 4 月 24 日
I have 37 csv files. I need to read data from first row of all the 37 files and merge these 37 rows into one mat file.
Then I will read all the 2nd rows and merge them into one mat file.
I will keep reading the data till the last row of each csv file.
Name of my csv files are:
Col01_all
Col02_all
.
.
.
Col37_all
I am not sure how to do this.
  7 件のコメント
KSSV
KSSV 2019 年 4 月 24 日
Are you sure that all A{i} are of same size?
Ahmad Hasnain
Ahmad Hasnain 2019 年 4 月 24 日
Yes, they are all of the same size 15x38

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2019 年 4 月 24 日
%your original code, slightly modified
csvfiles = dir('*.csv');
filescontent = cell(numel(csvfiles), 1);
for i = 1:numel(csvfiles)
filescontent{i} = csvread(csvfiles(i).name);
end
%write rows of matrices into mat file
destfolder = 'C:\somewhere\somefolder';
allcontent = cat(3, filescontent{:}); %concatenate all matrices into a 3D matrix
%save rows of each matrix into a mat file (as variable rows)
for rowidx = 1:size(allcontent, 1)
rows = permute(allcontent(rowidx, :, :), [3 2 1]); %extract rows.Permute so each matrix is a row of rows
save(fullfile(destfolder, sprintf('row%d.mat', rowidx)), rows);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by