Facing an error while using the Polyfit function

12 vues (au cours des 30 derniers jours)
Harshal Mehta
Harshal Mehta le 3 Juil 2017
Commenté : Image Analyst le 4 Juil 2017
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 commentaires
Walter Roberson
Walter Roberson le 4 Juil 2017
"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 le 4 Juil 2017
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.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 3 Juil 2017
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.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by