how do i store mutiple txt files into a 3d matrix
이전 댓글 표시
hi!,
im a highschool student whos very new to matlab and ive been assighned this task to store 3000 text files into one 3d matrix using the for loop command. I have no idea what im doing so any help is much appreciated!
댓글 수: 3
dpb
2022년 8월 10일
What is the content of each text file for starters...one presumes they are 2D arrays? It would be a pretty common (and handy) storage arrangment in MATLAB to place each 2D array as a plane in a 3D array.
That should provide some hints... :)
Good luck, give it a go and post back your efforts with specific Q? where you run into a specific problem. There's an <FAQ#How_can_I_process_a_sequence_of_files?> that you may find of benefit.
I'd note that hopefully the files have been named such that a wild card file specification with dir will give you the list of files over which to loop -- it's by far the simplest technique.
tina
2022년 8월 16일
@tina: you changed the original indexing into a 1, which is why you only store the first frame.
N = 3000;
M = nan(156,207,N);
for ii = 1:N
F = sprintf('frames_%d.txt',ii-1);
M(:,:,ii) = readmatrix(F);
end % ^^ compare this indexing
답변 (1개)
David Hill
2022년 8월 16일
Matrix=zeros(156,207,3000);
for i = 1:3000
Matrix(:,:,i)=readmatrix(['frames_' num2str(i-1) '.txt']);
end
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!