Upload files with almost the same name in different components of a matrix

1 回表示 (過去 30 日間)
Roderick
Roderick 2022 年 11 月 28 日
編集済み: Roderick 2022 年 11 月 28 日
Dear all
Let's imagine that I have multiple files in my current folder, which are as follows: spins-00000000.data, spins-00000001.data, spins-00000002.data, ..., spins-00000132.data. It is important to note that, although the number is added one by one, there are always eight digits. How could I make something like that happen without having to load the files one by one?
spin(:,:,1)=load('D:\Magnetic-Distribution\spins-00000000.data');
spin(:,:,2)=load('D:\Magnetic-Distribution\spins-00000001.data');
...
How could I do this efficiently?

回答 (1 件)

David Hill
David Hill 2022 年 11 月 28 日
for k=1:1e4
s=sprintf('%08d.txt',k);
spin(:,:,k)=load(['D:\Magnetic-Distribution\spins-',s]);
end

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by