Merge 864 single column text files and 60,000 rows in single file. How to get a matrix with 60000 rows and 864 column

1 次查看(过去 30 天)

I have 864 single column text files with 60,000 row in single text file.i would like to get a matrix with 60000 rows and 864 columns. Please help me

  3 个评论

请先登录,再进行评论。

采纳的回答

dpb
dpb 2022-8-9
编辑:dpb 2022-8-9
It would be simpler if you had named the files so they would sort lexically as C001, C002, ... etc., but it's still not too bad...
N=864; % the number files -- better/more general would be to use dir() and count number returned
L=60000; % length of each -- better/more general would be to read first and determine its length
M(L,N)0; % preallocate the output array to those sizes
for i=1:N
fname=char("C"+i+.txt);
M(:,i)=readmatrix(fname);
end
If the filenames were in proper normalized format, I'd be inclined to use the OS to copy and concatenate all into one long file, then read and reshape the resulting long vector instead of the loop...
  5 个评论
dpb
dpb 2022-8-11
You can type as easily as I ... you've got to put at least SOME effort into solving your own problems rather than relying on being spoon-fed.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by