How to import specific columns from multiple text files into a single numeric array?

5 ビュー (過去 30 日間)
Hi,
I am extremely new to Matlab and have a question on how to import specific columns from multiple text files into a single numeric array. I have 5 text files all in a single directory. I would like to read in the second column of numbers from each of these 5 files into a single numeric array and export that array to a new text file with a new name. Is there a simple way to do this?
Thanks!

採用された回答

David Hill
David Hill 2021 年 1 月 26 日
newFile=[];
for k=1:5
a=readmatrix(sprintf('yourFile%d.txt',k));%name files consistently with number at end
newFile=[newFile;a(:,2)];
end
save('newFile.txt','newFile','-ascii');
  1 件のコメント
Marcella Roth
Marcella Roth 2021 年 1 月 27 日
Thank you so much for your help! This put the column 2 from each of the 5 files into a single column. Is there a way to put the column 2 from each of the 5 files into a separate column in the same file?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by