フィルターのクリア

Read multiple .CSV files with csvread using a loop

19 ビュー (過去 30 日間)
Carlos_conde
Carlos_conde 2021 年 2 月 10 日
コメント済み: Carlos_conde 2021 年 2 月 10 日
Dear All,
I hope that you may help me,
Say I have n files named "droplet.n.csv" where n goes from 0 to 100 ( I am attaching five .csv files)
Each file has two rows. I want to extract the second row of each file and save it in another file. So what I would end up having on MATLAB is a matrix with many rows as n there are (in this case 100)
Thanks in advance

採用された回答

Stephen23
Stephen23 2021 年 2 月 10 日
編集済み: Stephen23 2021 年 2 月 10 日
V = 0:4;
N = numel(V);
C = cell(1,N);
for k = 1:N
F = sprintf('droplet.%d.csv',V(k));
C{k} = readmatrix(F,'NumHeaderLines',1);
end
M = vertcat(C{:})
M = 5×14
0 0 0 -0.0000 -0.0000 -0.0000 0.0000 0.0708 0 0 0 0.0130 0.0115 0.0117 0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0202 0.0000 -0.0000 0.0000 0.0130 0.0115 0.0117 0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0035 0.0000 0.0000 0.0000 0.0152 0.0115 0.0128 0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0118 0.0000 -0.0000 0.0000 0.0167 0.0115 0.0132 0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0130 0.0000 -0.0000 0.0000 0.0177 0.0115 0.0134
Or use readtable to get a table at the end, which might be more convenient to use.
  1 件のコメント
Carlos_conde
Carlos_conde 2021 年 2 月 10 日
You are a legend! thanks a lot

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by