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

2 views (last 30 days)
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!

Accepted Answer

Star Strider
Star Strider on 21 Nov 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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!