how do i store mutiple txt files into a 3d matrix

2 ビュー (過去 30 日間)
tina
tina 2022 年 8 月 10 日
編集済み: Stephen23 2022 年 8 月 16 日
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 件のコメント
tina
tina 2022 年 8 月 16 日
hey! i took some help from a friend and they told me to use this code, but my issue with thise code is that only the first frame is loaded properly and the rest when loaded are loaded as zeros and not with the numbers in the original text frame. My frames are 2D with just a ton of numbers and there are 3000 of them, how do i fix this issue?
Matrix=zeros(156,207,3000);
for i = 1:3000
Matrix(:,:,1)=load(['frames_' num2str(i-1) '.txt']);
end
Stephen23
Stephen23 2022 年 8 月 16 日
編集済み: Stephen23 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
David Hill 2022 年 8 月 16 日
Matrix=zeros(156,207,3000);
for i = 1:3000
Matrix(:,:,i)=readmatrix(['frames_' num2str(i-1) '.txt']);
end

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by