matlabmeanlatitude-longitudedimensionsmat-file

Mean of several .mat files of a 3-D Matrix


I have several .mat files, which are all in a 3-D matrix of latitude x longitude x value (70 x 70 x 8760).

It looks like this: year2000.mat --> (72 x 70 x 8760), year2001.mat --> (72 x 70 x 8760),until year 2020

I need the long-term mean along the third dimensions-the value. The result should be again a .mat file with 3-Dimension (72 x 70 x 8760). The first and second dimensions don't change.

I am very new to Matlab.


Solution

  • you did well in loading the files but since you know all the files start with year you can do:

    fn = dir('year*.mat');
    

    Then, you load the files, but if I understand you correctly you want to mean the years, not each year. so,

    data = zeros(72,70,8760);
    for n=1:numel(fn)
          single_year = load(fn(n).name);
          data = data + single_year.variable ; 
     end
    

    is variable really the name if the variable in each mat file? I just used what you wrote, but you should check what you get if you load a single file.

    now the avg is just the sum over the n:

     data=data./numel(fn);