0

In order to find best fit (thru polyfit), i am getting negative p value but matlab is not accepting it (Subscript indices must either be real positive integers or logicals.). Is there any way that I can use it ? I can't think of alternative method. I'll always get negative values.

EDIT:

I am trying to flattening baseline of a curve, for that. I am running for loop to have fit from 1 to 3 order. And then I am using smallest normr s value to to find the best fit and then subtract it from the whole curve to get baseline straight. I tried with few curves it works well but not with all of the data because of above describes issue.

part of the code I am working on:

for i=1:3 
  [p,s]=polyfit(x,y,i); 
  a=s.normr; 
  b(i,1)=p(1); 
  normr(i,1)=a; 
  ind=find(b==min(b)); 
  mn=b(ind,1); 
  Yflat=y-mn(1)*(x-mean(x)); 
  ca{2,2}=Yflat; 
  clear a b normr p s rte ind ind2 Yflat 
end  
1
  • 2
    What are you using p for? You should include that code. Commented Mar 27, 2013 at 18:18

2 Answers 2

1

When I translate an image into negative coordinates,

I usually record an offset e.g. offset = [ -5, -8.5 ] and save the intensity values in matrix begin with (1, 1) as usual,

But when comes to calculation, let the coordinates array add up with the offset

e.g. [ actualX, actualY ] = [ x, y ] + offset ;

It may need extra efforts, but it works.

Good Luck!

Sign up to request clarification or add additional context in comments.

Comments

0

The code below (your code from the comments + initialization of x, y) executes. What is the problem?

x = 1:50;
y = randn(size(x));

for i=1:3
    [p,s]=polyfit(x,y,i);
    a=s.normr;
    b(i,1)=p(1);
    normr(i,1)=a;
    ind=find(b==min(b));
    mn=b(ind,1);
    Yflat=y-mn(1)*(x-mean(x));
    ca{2,2}=Yflat;
end

1 Comment

ya there is no problem, before posting it i cleaned it up...maybe some extra variables that i had they were creating problem..thanks..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.