How to extract a value out of different .mat files and save them into an array
26 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
lunduz
el 24 de Nov. de 2019
Respondida: TADA
el 24 de Nov. de 2019
I have to load multiple .mat files, and in those files I want to get the same value out, and then place it into an array
for examle I have 5 files
load('my_file_1.mat');
load('my_file_2.mat');
load('my_file_3.mat');
load('my_file_4.mat');
load('my_file_5.mat');
and in each of this 5 files is the same variable, that hat in each case an other value, and I want those values saved into an arry.
How can I do that, i'm stuck?
Thanks in advance!
0 comentarios
Respuesta aceptada
TADA
el 24 de Nov. de 2019
s = load('my_file_5.mat');
will return a struct, each variable in the file will be put in a field in that struct
if all files have the same fields, you can put them all in a struct array:
for i = 5:-1:1
s(i) = load(['my_file_' num2str(i) '.mat');
end
if you are only interested in specific variables from each file you can tell load to only load the variables you need, like that:
s = load('my_file_5.mat', 'X', 'Y'); % if the variables are called X and Y for instance
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!