MATLAB: Average a large number of matricies from .mat files

Join the discussion
Registration is free. Start your own thread to ask a follow-up.
2 replies · 11K views
Hoplite
Messages
50
Reaction score
0
I have a series of large 2x2 matricies, each of which is stored inside a .mat file. These files have the names data1.mat, data2.mat, data3.mat,..., data60.mat. I have sucessfully loaded each of these .mat files.

I want to create a 1x60 array whose entires are the average values of the matrices. i.e:

average(1) = mean(mean(data1));
average(2) = mean(mean(data2));
etc.

If I average the .mat files individually as above, it works, but I want to write a shot code which averages them all. I can make a string containing the names of the .mat files via

names = strseq('data',1:60)

This gives me an array with entries

name(1)=data1
name(2)=data2
etc.

However, when I try to use eval(name(1)) to call the .mat file, it doesn't work. It gives me the message

"? Undefined function or method 'eval' for input arguments of type 'cell'."

I take it that it is not recognising "name(1)" as a reference to the matrix data1. I'm not even sure that it's actually recognising name(1) as the string data1.


It would be great if anyone could explain what I'm doing wrong, or suggest another way to call these .mat files.
 
Physics news on Phys.org
Try using eval(name{1})

note the curly brackets after name.