i have my problem to work with functions. do not get any results from it. I know that it work, so the problem is just by my execution of the function.
How can i avoid following error?
>> ref_model(1,2)
Index exceeds the number of array elements (2).
Error in ref_model (line 7)
I=p(2)./(d(:,1)+p(1))+p(3)./(d(:,1)+p(1)).^2+p(4)./(d(:,1)+p(1)).^4;
>> myQ(1)
Index in position 2 exceeds array bounds.
Error in myQ (line 5)
Q=sum(r(:,1).*(ref_model(x,r(:,1))-r(:,2)).^2);

 채택된 답변

KSSV
KSSV 2021년 8월 26일

1 개 추천

From the function r should be a m*2 matrix. It should have two columns. And x should be a 1*4 array.

댓글 수: 7

thanks for your support but i do not work:
>> x=[1 2 3 4]; myQ(x)
Index in position 2 exceeds array bounds.
Error in myQ (line 5)
Q=sum(r(:,1).*(ref_model(x,r(:,1))-r(:,2)).^2);
KSSV
KSSV 2021년 8월 26일
r = rand(10,2) ;
global r ;
x = 1:4 ;
Q = myQ(x) ;
Try avoiding gloabl, instead you can make it as a input to function.
Elisbeth Brandner
Elisbeth Brandner 2021년 8월 27일
thanks a lot :) ! now i have a solution. i changed my function and now it works
darova
darova 2021년 8월 29일
KSSV
KSSV 2021년 8월 29일
@darova you can accept the answer as well.
Walter Roberson
Walter Roberson 2021년 8월 29일
For the first 10 days, only the person who asked the Question can Accept an Answer.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 8월 26일

댓글:

2021년 8월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by