How to write a for statement for multiple .mat files?

2 visualizaciones (últimos 30 días)
Paul Scotti
Paul Scotti el 21 de Nov. de 2015
Respondida: Star Strider el 21 de Nov. de 2015
I have 6 .mat files each with different file names. I am able to import them into the workspace but I am having difficulty figuring out how I am supposed to run analyses on particular columns or rows for each .mat file in succession.
For instance, with something like this, I don't know what I'm supposed to do in order to have TrialNum equal all the values of the first column for each .mat file.
for i=1:6
TrialNum = %all the values for the 1st column of each .mat file
end
I apologize for the basic question, I'd really appreciate any help!

Respuesta aceptada

Star Strider
Star Strider el 21 de Nov. de 2015
I’m not certain how you’re importing them (using load obviously), but with or without an output argument. If you load them with an output argument in a loop with index ‘k’, e.g.:
D{k} = load('Data1.mat');
they will load as a structure in ‘D’. You can load only specific variables as well. (See the documentation for load for those details.) You can then dissect out the variables of interest from the structure for each file, and define the appropriate columns.
I have only the information you supplied, so I can’t be more specific.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by