# Function returning matrix instead of vector

조회 수: 2 (최근 30일)
답변: Rafael Hernandez-Walls 2020년 6월 17일
Hello,
I have made a function for use in least squares curve fitting of the form:
f=@(xf,xdata)xf(1)*(xf(4)+((xf(2)-xdata)/(xf(3)/2))).^2/(1+((xf(2)-xdata)/(xf(3)/2)).^2)
xf should have 4 parameters
When I test the function with
f(x0f,xdata)
with x0f = [1.0000, 462.7580, 1.8007, 0], and xdata a 15x1 column vector I get a 15x15 matrix as output, when I expect a 15x1 column vector. I believe the issue is that the f function has xdata squared (.^2) both in the numerator and denominator, but I don't know how to circumvent this as there is no way to isolate xdata. Any help is appreciated.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
P.S. Entering this function into lsqcurvefit results in an error "Function value and YDATA sizes are not equal."

댓글을 달려면 로그인하십시오.

### 채택된 답변

KSSV 2020년 6월 17일
편집: KSSV 2020년 6월 17일
Repalce * with .*, / with ./
f=@(xf,xdata)xf(1)*(xf(4)+((xf(2)-xdata)./(xf(3)/2))).^2./(1+((xf(2)-xdata)./(xf(3)/2)).^2) ;

댓글을 달려면 로그인하십시오.

### 추가 답변 (1개)

Rafael Hernandez-Walls 2020년 6월 17일
f=@(xf,xdata)xf(1)*(xf(4)+((xf(2)-xdata)/(xf(3)/2))).^2./(1+((xf(2)-xdata)/(xf(3)/2)).^2)

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Curve Fitting Toolbox에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by