Error using lsqcurvefit (line 269) Function value and YDATA sizes are not equal

4 vues (au cours des 30 derniers jours)
ANTONIO JIMENEZ RECIO
ANTONIO JIMENEZ RECIO le 3 Avr 2021
Réponse apportée : Arjun le 2 Juin 2025
Hi, im new inMATLAB. Im doing a curve fitting using lsqcurvefit but it dosent work.
My script is:
ang_f=data2(:,1);
w_f=2*pi()./data2(:,3);
fun= @(x,w_f) x(1)./(((x(2).^2-w_f.^2)+4.*x(3).^2*w_f.^2).^(1/2));
x0=[11,3.5,1];
x=lsqcurvefit(fun,x0,w_f,ang_f);
Thanks

Réponses (1)

Arjun
Arjun le 2 Juin 2025
The issue is that the output of function "fun" doesn't match the size of the "ang_f" data. This typically happens when the function you are using to fit the data does not return a vector of the same length as the input "ang_f" data you are trying to model. To fix this you will have to modify "fun" to output vector of dimensions that matches dimensions of "ang_f".
It will be helpful to debug if you attach data.
I hope this helps!

Catégories

En savoir plus sur Matrix Computations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by