Hi there,
I have a matrix 8760x8 and I would like to fit the data of each row (8 values) with a vector like this: [1 2 3 4 5 6 7 8]
Is it possible to do it ?
thanks

1 Kommentar

Stephen23
Stephen23 am 27 Jun. 2017
@Nikolas Spiliopoulos: and what is the expected output of this "fitting"?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

dpb
dpb am 27 Jun. 2017
Bearbeitet: dpb am 27 Jun. 2017

0 Stimmen

Guessing the intent Stephen has asked for,
x=1:8; % the independent variable vector
nrow=size(data,1); % rows in data array (8760 but don't use "magic numbers)"
coeff=zeros(nrow,2); % preallocate for the coefficient array
for ix=1:nrow
coeff(ix,:)=polyfit(x,data(ix,:),1); % coefficients of linear fit on each row
end
See
doc polyfit
doc polyval
for details on them. Could also use fit if have Curve Fitting TB and return a fit object containing the coefficients and other info as alternative. If do go this route will have to pass x,row vector as columns.
None of the fitting tools are fully vectorized to do the fit on an array of columns so do need to iterate over the array.

3 Kommentare

Nikolas Spiliopoulos
Nikolas Spiliopoulos am 27 Jun. 2017
Hi again,
thanks for the answer. I tried it but I get this error:
Error in (line 10) coeff(i,:)=polyfit(x,annual_temperature_data(i,:),1);
"Subscript indices must either be real positive integers or logicals"
"annual_temperature_data" is my data vector of 8760x8
thanks
Typo --
coeff(ix,:)=polyfit(x,annual_temperature_data(ix,:),1);
i is the Matlab builtin sqrt(-1).
Daniela Conforti
Daniela Conforti am 16 Jan. 2019
Bearbeitet: Daniela Conforti am 16 Jan. 2019
Hi, you know how can I use "polyfit" whitout using a for-loop?
I have the same problem described in this question but I'm using a matrix with millions of rows, therefore it requires a lot of time.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 27 Jun. 2017

Bearbeitet:

am 16 Jan. 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by