1

Hi I'm trying to fit a power model to my data using MatLab's fit function

fo = fit(log2(x(:)),log2(y(:)),'power1');
plot(fo,'g'), hold on

However when I run this I get the error

Error using fit>iFit (line 282)
Cannot fit Power functions to data where X has nonpositive values.

Error in fit (line 108)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ... 

Error in CurvedPowerLaw (line 20)
fo = fit(log2(x(:)),log2(y(:)),'power1');

When looking at my data and checking if any are less than 1, nothing is displayed

x(count_1)=M(i,1);
y(count_1)=M(i,2);
count_1= count_1+1;
if(M(i,2)<1)
    display(M(i,1))
end;

M is a csv file with two columns. I also re ran the code for

if(M(i,1)<1)

and nothing was displayed. Checking manually and nothing seemed to be below 1 either.

i is just the line in the file that is being parsed. The file looks like

344,17
345,13
346,13
347,16
340,12

M(i,1) will result in returning one of the >300 numbers and M(i,2) will return ~10 value Any help would be much appreciated!!

Thanks

Dunny
  • 170
  • 12
  • What's `i`? Is this some sort of a loop index? What is `M(i,1)`? A scalar? a vector? What do you expect the behavior of `if([0 1 0 0 1])` to be? Please provide a [mcve] in your question. Did you try to reproduce the problem in `cftool`? – Dev-iL Mar 15 '17 at 13:35
  • i is just the line in the file that is being parsed. The file looks like 344,17 345,13 346,13 347,16 340,12 M(i,1) will result in returning one of the >300 numbers and M(i,2) will return ~10 value – Dunny Mar 15 '17 at 16:05
  • Please include an example that is **runnable by other people** _and_ **reproduces your problem**. Your comment is information that is missing from the question, so please [edit](http://stackoverflow.com/posts/42807490/edit) the question to include it. – Dev-iL Mar 15 '17 at 16:24

1 Answers1

0

While all values that were parsed in were >0 when scaling them by log2 that's where the 0 values started appearing. A quick fix was to add 1 to each value when parsing them in.

Dunny
  • 170
  • 12