Create loop to load .mat file and store values to a matrix.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stylianos Gallidis
el 6 de Dic. de 2021
I have multiple .mat files with values for x and y. The variables in each file has the same name (x,y) , but different values.
I need to create a loop or a function that loads each file and will open them one at a time and save x and y (maybe in a matrix) in order to be able to plot them. Any thoughts?
0 comentarios
Respuesta aceptada
Stephen23
el 7 de Dic. de 2021
Editada: Stephen23
el 7 de Dic. de 2021
This should get you started. In the absence of any data desription I assumed that withinin each file x and y are scalar. You will need to adapt to suit your filenames, data sizes, etc.:
P = 'absolute or relative file path to where the files are saved';
S = dir(fullfile(P,'*.mat'));
S = natsortfiles(S); % optional, if required download from FEX 47434.
for k = 1:numel(S)
F = fullfile(P,S(k).name);
S(k).data = load(F);
end
D = [S.data];
X = vertcat(D.x);
Y = vertcat(D.y);
plot(X,Y)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!