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!