Calculate trend values by regression in MATLAB

171 Views Asked by At

I have a matrix with dimensions of 19 rows and 7541502 columns. I want to get the trend of each column using regression. This is possible by using MATLAB function but requires a lot of time. The written function is as follows:

Data = box1;
[r, c] = size(Data);
X = [1:r]'; Total = [];
for j = 1:c;
   Y = Data(:, j);
   [b1, bint1] = regress(Y, [ones(size(Y)) X]);
   Qs = [bint1(2, :), b1(2, :)];
   Total = [Total; Qs];
end

Is there a way to speed up Mfile in MATLAB? Is there a way to calculate regression without using functions?

Thanks in advance.

enter image description here

1

There are 1 best solutions below

2
On

Try initializing Total to be the correct size before entering the for loop.

Total = zeros(c, 2);

instead of:

Total = [];