Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Jun 4, 2009 #1
    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));

    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


    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.
  2. jcsd
  3. Jun 4, 2009 #2
    Try using eval(name{1})

    note the curly brackets after name.
  4. Jun 4, 2009 #3
    That really works!

    Thanks, Matonski.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - MATLAB Average large Date
Matlab Coding angular spectrum of waves in a fluid Yesterday at 7:30 AM
How to program this in Matlab Feb 28, 2018
Matlab Making a short test for self-adjointness Feb 23, 2018
Matlab - averaging Jan 10, 2010