Search code examples
matlabmeannormalize

How to normalize each column to its mean value


I have one table with in y the regions, while in several years (2010, 2011, 2012, 2013 etc). Each year has one value for each region. I would like to nomalize the data of each column. Is it possible to normalize using the mean of the year? I tried this, but I am not sure.

t=readtable('Cartel3.xlsx')
t_norm a= normalize((t{2:end, 2:end}),'norm')

I have two tables with different data. I would like to compare them.I was asked to use the annual average to normalize. But it is not clear for me, the formula.

enter image description here

enter image description here


Solution

  • You can use normalize directly on your table providing you specify the 'DataVariables' parameter, like this:

    >> t = table(["A";"B";"C"], [1;2;3], [0;10;20], 'VariableNames', {'Name', '2011', '2012'})
    t =
      3x3 table
        Name    2011    2012
        ____    ____    ____
        "A"      1        0 
        "B"      2       10 
        "C"      3       20 
    >> normalize(t, 'DataVariables', t.Properties.VariableNames(2:end))
    ans =
      3x3 table
        Name    2011    2012
        ____    ____    ____
        "A"      -1      -1 
        "B"       0       0 
        "C"       1       1 
    

    There's a specific example like this on the doc page.