how to read multiple file from single .mat file

2 ビュー (過去 30 日間)
Sun Heat
Sun Heat 2021 年 6 月 9 日
コメント済み: Sun Heat 2021 年 6 月 11 日
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
  1 件のコメント
Sun Heat
Sun Heat 2021 年 6 月 9 日
thanks in advance....

サインインしてコメントする。

採用された回答

Jan
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.
  1 件のコメント
Sun Heat
Sun Heat 2021 年 6 月 11 日
thanks a lot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by