Facing an error while using the Polyfit function

조회 수: 6 (최근 30일)
Harshal Mehta
Harshal Mehta 2017년 7월 3일
댓글: Image Analyst 2017년 7월 4일
I am facing an error while executing a script.. Here's the part where I am getting the error:
Code:
ind=find(abs(mzf-mz(rng)') > 7);
mz(rng(ind))=mzf(ind);
rng=imn-50:imn+50;% This is a range of our data at minimum MZ
warning off *
pp=polyfit(p(rng),mz(rng)',3);
warning on
mzf=polyval(pp,p(rng));
ind=find(abs(mzf-mz(rng)') > 7);
mz(rng(ind))=mzf(ind);
Error:
Index exceeds matrix dimensions.
Error in test2 (line 68)
pp=polyfit(p(rng),mz(rng)',3);
  댓글 수: 5
Walter Roberson
Walter Roberson 2017년 7월 4일
"No, I have given you only the snippet of the code."
It isn't worth our time to play guessing games on what the size and data types of the variables are, or what the value of imn is at the time of the error or how it might have reached that value in a way that was contrary to your expectations.
imn is somehow within 50 of the end of the p or mz arrays. That is about all we can say without further information.
Image Analyst
Image Analyst 2017년 7월 4일
I use the compiler all the time. It is very expensive. So I suggest you get your money's worth and call the Mathworks for technical support. You've already paid for it so why not take advantage of it? See the FAQ: http://matlab.wikia.com/wiki/FAQ#My_standalone_executable_won.27t_run_on_the_target_computer._What_can_I_try.3F first.

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

답변 (1개)

Image Analyst
Image Analyst 2017년 7월 3일
x and y must be the same shape, not like one is a row vector and the other a column vector. So if p is a row vector, then mz must be a column vector since you transpose it. Otherwise you get a size mismatch error.
And like Walter said, rng is a built-in function, random number generator. You should not name your variables after built-in functions. Try renaming your rng to "indexes" or something and see if it works.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by