0

This is the script I have thus far:

inpdata = log(tower_wind_GF_2001);
inpdata = inpdata(~any(isnan(inpdata),2),:);
inpdata = inpdata(~any(isinf(inpdata),2),:);

names = {'trend10' 'trend20' 'trend40' 'trend80' 'trend120' 'trend200'};
names2 = {'slope10' 'slope20' 'slope40' 'slope80' 'slope120' 'slope200'};

for i = linspace(2,12,6);
    for j = linspace(3,13,6);
            for varname = 1:length(names)
                for varname2 = 1:length(names2)

                    p = polyfit(inpdata(:,i), inpdata(:,j), 1);
                    slope = p(1);
                    int = p(2);
                    trend = slope*inpdata(:,i) + int;
                    trend = real(trend);
                    trends.(names{varname}) = trend;
                    slopes.(names2{varname2}) = slope; 

                end
            end
    end
end

Where the inpdata matrix has consecutive columns holding two parameters at 6 different heights. For instance,

inpdata(:,2) 

and

inpdata(:,3) 

are the two parameters for the 10 m height.

The script however will the same vector for trend10 and trend20 etc. Do I have to preallocate or store the vectors in a cell array before? I was under the assumption that the loop would run through all calculations, assign the variable name and then move onto the second value in i and j but clearly I am wrong.

MANY THANKS!

NirMH
  • 4,477
  • 2
  • 40
  • 64
user2013373
  • 101
  • 2
  • 8

0 Answers0