Facing an error while using the Polyfit function
이전 댓글 표시
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
2017년 7월 3일
You have not given us any reason to expect that the index will be in range. You have not shown us the array sizes or initial values of the variables. Also, you start out with rng being a function but then you assign a value to it, turning it into a variable.
Harshal Mehta
2017년 7월 4일
Walter Roberson
2017년 7월 4일
Compilation errors for data files usually involve data files that cannot be found at the location named, or which there are permission errors in locating. Otherwise you tend to get run time errors instead of compilation errors.
Are you using MATLAB Compiler SDK or MATLAB Commpiler? Which release are you using? What is the compilation error?
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
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
2017년 7월 3일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!