how to read multiple file from single .mat file

2 visualizaciones (últimos 30 días)
Sun Heat
Sun Heat el 9 de Jun. de 2021
Comentada: Sun Heat el 11 de Jun. de 2021
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

Respuesta aceptada

Jan
Jan el 9 de Jun. de 2021
Editada: Jan el 9 de Jun. de 2021
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.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by