Using polyfit subscripts in editor?
1 view (last 30 days)
Show older comments
Hi,
I'm trying to write a script in editor which calls for a polyfit function, but it always returns an error that the subscript must be positive integer or logical. I've tried changing all the variables in the function, but it wont change the error. I'm not sure how to fix it. The code used to work in the command window.
Part of the code where it trips:
ind=find(abs(mzf-mz(rng)') > 7); mz(rng(ind))=mzf(ind); rng=imn-50:imn+50; 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 is in bold. I've asked my team mates and a lecturer, but no answers as yet.
Thanks!
0 Comments
Answers (3)
Image Analyst
on 6 Dec 2013
You forgot to give the error. Please copy and paste all the red text - don't snip/clip/paraphrase it - give all of it to us.
Then, before the pp= line where the error occurs, put these lines:
rng % Don't use a semicolon so it will print to command window.
whos rng
Tell us what it says in the command window. If rng is huge, then just put rng(1:10) or some small chunk of it.
0 Comments
John D'Errico
on 6 Dec 2013
There are TWO possibilities, and only you can resolve it.
...
Columns 66 through 78
289 290 291 292 293 294 295 296 297 298 299 300 301
Columns 79 through 91
302 303 304 305 306 307 308 309 310 311 312 313 314
Columns 92 through 101
315 316 317 318 319 320 321 322 323 324
Subscript indices must either be real positive integers or logicals.
Error in sweeper (line 90) pp=polyfit(p(rng),mz(rng)',3);
I've excerpted some of what you have given us, the important part.
1. rng is not composed of integers, and you are trying to subscript into arrays p and mz with a non-integer subscript.
Test for the above by something like this:
any(rng ~= round(rng))
or
any(rem(rng,1) ~= 0)
Put this line in before the call to polyfit, or use the debugger to step through the code up to that line. Or set
dbstop if error
before you run the code. This will drop you into the debugger when the error occurs.
2. The second possibility, is that you have created an array with the name polyfit. This will confuse matlab and cause that error message. DON'T DO IT.
0 Comments
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!