how to read multiple file from single .mat file
1 回表示 (過去 30 日間)
古いコメントを表示
i have 16 different file in "data2-18.mat", like M1,M2,M3,M4.......M16. i want to call every file(i.e., M2 ,M6, M5...) in loop according to variable "A" (in program).
clc;clear all;
load data2-18
A=[2 6 5 8 9];
for i=1:5
data1 = M(A(i));
F1=data1(:,1);
E1=data1(:,2);
Ei1=data1(:,3);
M1=data1(:,4);
Mi1=data1(:,5);
Ereal=complex(E1,Eimg1);
Mreal=complex(M1,Mimg1);
end
採用された回答
Jan
2021 年 6 月 9 日
編集済み: Jan
2021 年 6 月 9 日
I assume you use the term "file", but you mean "variable".
Calling load() without catching the output, creates variables dynamically. This has a lot of severe disadvantages. One of the worst is that it impedes debugging, because you cannot know be reading the code, where a variable is coming from. Better:
FileData = load('data2-18.mat');
A = [2 6 5 8 9];
for i = 1:5
data1 = FileData.(sprintf('M%d', i));
...
Avoid hiding indices in names of variables. Use arrays an indices.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!