Matlab wont extract first row & column because of matrix dimensions !

Posted by ZaZu on Stack Overflow See other posts from Stack Overflow or by ZaZu
Published on 2010-05-16T03:14:47Z Indexed on 2010/05/16 3:20 UTC
Read the original article Hit count: 322

Filed under:
|

Hey guys,

I am tracking an object that is thrown in air, and this object governs a parabolic pattern. Im tracking the object through a series of 30 images. I managed to exclude all the background and keep the object apparent, then used its centroid to get its coordinates and plot them. Now im supposed to predict where the object is going to fall, so I used polyfit & polyval .. the problem is, matlab says ??? Index exceeds matrix dimensions.

Now the centroid creates its own structure with a row and 2 columns. Everytime the object moves in the loop, it updates the first row only ..

Here is part of the code :

For N=1:30
.
.
.
x=centroid(1,1); % extract first row and column for x
y=centroid(1,2); % extract secnd row and column for x
plot_xy=plot(x,y)
set(plot_xy,'XData',x(1:N),'YData',y(1:N)); 
fitting=polyfit(x(1:N),y(1:N),2);
parabola=plot(x,nan(23,1));
evaluate=polyval(fitting,x);
set(parabola,'YData',evaluate)
.
.
end

The error message I get is

??? Index exceeds matrix dimensions.

It seems that (1:N) is causing the problems .. I honestly do not know why .. But when I remove N, the object is plotted along with its points, but polyfitting wont work, it gives me an error saying :

Warning: Polynomial is not unique; degree >= number of
data points. 
> In polyfit at 72

If I made it (1:N-1) or something, it plots more points before it starts giving me the same error (not unique ...) .

Any ideas why ??

Thanks alot !!

© Stack Overflow or respective owner

Related posts about matlab

Related posts about image-processing