need help with array as input parameter of a function
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi, I am trying to build a Matlab function which has input parameter as arrays. This function calculate the slope and intercept of a line through 2 point. I use an array of 2 element (x,y) for a point. This is my function:
function [slope,intercept]=analyzeLine(point1,point2)
if(point1(1)==point2(1))
slope=pi/2;
intercept=0;
else
slope=(point1(2)-point2(2))/(point1(1)-point2(1));
intercept=(point1(1)*point2(2)-point1(2)*point2(1))/
(point1(1)-point2(1));
end
But when I compile the error says:
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
Please let me know what I did wrong and what should I do.
Thank you so much! Best regards, Thang
댓글 수: 0
답변 (2개)
Walter Roberson
2011년 4월 4일
How exactly are you calling the routine? Could you give a specific numeric example?
댓글 수: 0
Matt Fig
2011년 4월 4일
I have never seen that error message before. How are you calling the function?
BTW, what version of MATLAB are you using?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!