Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 794159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:16:18+00:00 2026-05-14T22:16:18+00:00

I am tracking an object that is thrown in the air, and this object

  • 0

I am tracking an object that is thrown in the air, and this object governs a parabolic pattern. I’m 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 I’m 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 two 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 won’t 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 …). But I can’t remove (1:N), because I have to evaluate the coefficients of the polynomial in each loop (each value of N), so what’s the solution?

Edit 2 :

This is more of my code

for N = 1:30
    hold on
    I = figure.image.(['j' num2str(N)]);
    bw = (I);
    imshow(bw)
    ss = bwlabel(bw);
    s = regionprops(bw,'centroid');
    centroids = cat(1, s.Centroid);
    hold(imgca,'on')
    plot(imgca,centroids(1,1), centroids(1,2),'r*')
    x = centroids(1,1);
    y = centroids(1,2);
    points = plot(x,y,'bo',x,y,'rx');
    hold on;

    for N>3
        C1 = centroids(1,1);
        C2 = centroids(1,2);
        set(points,'XData',C1,'YData',C2);
        poly = polyfit(C1,C2,2);
        parabola = plot(C1,nan(size(centroids,1),1));
        pval = polyval(poly,x);
        set(parabola,'YData',pval);
        pause(0.5)
    end
end

Edit 3

Code to display object distination:

poly = polyfit(C1,C2,2);
g = roots(poly);
v = max(g)
plot(xPlot,polyval(poly,xPlot),'y')
plot(v,'go')

The parabola line is plotted correctly due to xPlot, but for g (the prediction), it all goes wrong… Am I using the wrong syntax to get the max value?

Alt text

I also realized if I put plot(g,'g--') instead of v, I get:
Wonder if I can get this horizontal instead of vertical. Then I will have a line with a circle where the parabola is predicted to stop.

Alt text

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:16:18+00:00Added an answer on May 14, 2026 at 10:16 pm

    This is how your code should look like, if I correctly understand what you want to do:

    %# if there is only one centroid per image, preassign centroid array like this
    centroids = zeros(30,1); %# case A
    
    %# if there can be any number of centroids per image, preassign like this
    centroids = cell(30,1); %# case B
    
    for N=1:30
        hold on
        I = figure.image.(['j' num2str(N)]);
        bw=(I);
        imshow(bw)
        ss = bwlabel(bw);
        s = regionprops(bw,'centroid');
    
        %# for case A
        centroids(N,:) = cat(1, s.Centroid);
        %# for case B
        centroids{N} = cat(1,s.Centroid);
    
        hold(imgca,'on')
    
        %# case A
        plot(imgca,centroids(N,1), centroids(N,2),'r*')
        %# case B
        if ~isempty(centroids{N})
           plot(imgca,centroids{N}(:,1), centroids{N}(:,2), 'r*');
        end
    
        %# I don't think the following lines do anything useful
        x=centroids(1,1); 
        y=centroids(1,2); 
        points=plot(x,y,'bo',x,y,'rx');
    
        %# update plots
        drawnow
    
       %# you can only do the fitting once you collected all centroids
    
    end
    
    %# case A - do nothing b/c centroids is already numeric
    %# case B - catenate centroids to make a numeric array with 2 columns
    centroids = cat(1,centroids{:});
    
    
        C1=centroids(:,1);
        C2=centroids(:,2);
        %#set(points,'XData',C1,'YData',C2); 
        poly=polyfit(C1,C2,2); 
        %# you can use the output of polyval directly as y-coordinate
        parabola=plot(C1,polyval(poly,C1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just threw this little mouse tracking example together when I realized, that it
I'm writing bug tracking software in PHP, and today I saw this in another
Lately I've been tracking a spammer on craigslist. I recently discovered that he's added
The Async Tracking code in Google Analytics looks like this: var _gaq = _gaq
I want to add tracking to our Flash-based media player so that we can
I'm building an object tracking API for my team. My code will recognize foreground
I am making an object tracking application. I have used Emgucv 2.1.0.0 to load
I am doing a project called user initiated real time object tracking system .
I have a cache object property that I'd like to set to the current
Is there a way to disable LINQ's object tracking features, without also disabling lazy-loaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.