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

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.
No, I have given you only the snippet of the code. The thing which irritates me is that the code runs for one data-file whereas it shows a compilation error for an another data-file
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?
"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.
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일

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.

카테고리

질문:

2017년 7월 3일

댓글:

2017년 7월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by