Okay so I had a code which had an error, and I thought I fixed it, but now I'm getting another error in it
function [m1,m2]=mycomplexityplot(fh2,x2,N)time1=zeros(1,N);for i = 1:N tic for k1=1:i fh2(x2); end time1(i)=toc;endtime2=zeros(1,N);for i2=1:N tic for k2=1:i2 for k3=1:i2 fh2(x2); end end time2(i2)=toc;endn=1:N;loglog(n,time1,'b-')hold onloglog(n,time2,'g--')legend('1 loop','2 loops')xlabel('N')ylabel('time(s)')hold offp1=polyfit(n(length(n)/2:end),time1(n/2:end),1);p2=polyfit(n(length(n)/2:end),time2(n/2:end),1);m1=p1(1);m2=p2(1);
when i try to run: fh2=@sqrt; [m1,m2]=mycomplexityplot(fh2,5,100)
I get the errors:
Error using polyfit (line 48) X and Y vectors must be the same size.
Error in mycomplexityplot (line 35) p1=polyfit(n(length(n)/2:end),time1(n/2:end),1);
Error in TestCasesLab9 (line 2) [m1,m2]=mycomplexityplot(fh2,5,100
what can do to fix this? sorry for the repost!!
Best Answer