Error: ()-indexing must appear last in an index expression.

조회 수: 1 (최근 30일)
Taylor C
Taylor C 2017년 2월 27일
댓글: Guillaume 2017년 2월 27일
Hello,
I am currently stuck on a homework problem and could use some help.
I am supposed to write a function that takes as input 2 variables and outputs parameter estimates for the slope and bias of a cumulative Gaussian psychometric curve to fit to the data.
So far I have:
function [bias, slope] = psychometricFit(x, y)
p = normcdf(x, y, 1)
Gaussian = @(p,x) (0.5*erfc(x-p(1)/(p(2)(sqrt(2)))))
coefEst = nlinfit(x,y,Gaussian,[1 1])
end
I keep getting an error that says:
Error: File: psychometricFit.m Line: 3 Column: 37
()-indexing must appear last in an index expression.
I'm not sure how to fix this or "index" it properly.
Thank you
  댓글 수: 1
Stephen23
Stephen23 2017년 2월 27일
As well as the parentheses issue explained by Guillaume below, there is another problem: the third line defines p as an input to an anonymous function, and so the p on the second line
p = normcdf(x, y, 1)
is never used.

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

답변 (1개)

Guillaume
Guillaume 2017년 2월 27일
In your anonymous function what is
p(2)(sqrt(2))
meant to do? It's clearly not valid matlab. Perhaps you are missing an operator.
  댓글 수: 3
Taylor C
Taylor C 2017년 2월 27일
The cumulative Gaussain function is
f(x) = 1/2*erf((x-mu)/(sigma(sqrt(2)))
my teacher gave us a hint that mu is the parameter for the bias and sigma is the parameter for the slope
Guillaume
Guillaume 2017년 2월 27일
modelFun = @(p,x)*something
is not valid matlab either.
In
f(x) = 1/2*erf((x-mu)/(sigma(sqrt(2)))
sigma(sqrt(2)) is not even mathematically valid notation (unless sigma is a function, which it clearly isn't if it's the value of the standard deviation). The actual definition of the CDF of the normal distribution is:
f(x) = 1/2*erf((x-mu)/(sigma*sqrt(2))
As hinted in my answer, you are missing an operator.
See also, the comment by Stephen about p.

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by