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 5974571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:57:41+00:00 2026-05-22T20:57:41+00:00

I get the error ??? Index of element to remove exceeds matrix dimensions. Error

  • 0

I get the error

???  Index of element to remove exceeds matrix dimensions.

Error in ==> myfile at 111
    C(i)=s{i,3};

the code being:

C=zeros(num_of_tris,1);
for i=1:size(C,1)
    C(i)=s{i,3};
end

I’m not showing the code for creating s, but I assume it’s beside the point as s only appears on the right hand side of the assignment…

why does it say element to remove? which element am I removing?

  • 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-22T20:57:42+00:00Added an answer on May 22, 2026 at 8:57 pm

    Ok, so here’s what is happening. s is probably initialized to an empty cell (NOTE: need not be entirely empty — see last paragraph). So, indexing an element of s as s{i,3} returns []. The MATLAB operation to remove an element of a vector is

    C(i)=[];
    

    So when you loop through, you’re removing the elements of C one by one, and eventually, the index i exceeds the size of the (now diminished) vector.

    Here’s a small example that reproduces your problem:

    s=cell(10,5);           %#initialize s to an empty cell
    %#note that any cell returns []
    s{3,4}
    
    ans =
    
         []
    
    %#This is your code from above
    C=zeros(10,1);          %#initialize C
    for i=1:size(C,1)
        C(i)=s{i,3};
    end
    

    ??? Index of element to remove exceeds matrix dimensions.

    You’ll find that the index i when you get this error is numel(C)/2+1. In other words, till i=5 (in this example), you’re removing every odd element of C and at i=6, the number of elements remaining in C is 5, and so you get an index out of bounds error.


    NOTE:

    s need not even be entirely empty. Consider this example:

    s=cell(10,1);
    s([1,2,6,8])=num2cell(rand(4,1));
    C=zeros(10,1);
    for i=1:numel(C)
        C(i)=s{i};
    end
    

    ??? Index of element to remove exceeds matrix dimensions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run php-closure i get a PHP error Undefined index: HTTP_IF_NONE_MATCH in <b>/php-closure.php</b>
I am using following PHP code for trigger creation but always get error, please
If I set pre-compile script into binary code to true I get error saying
How do I unit test my code that has LTS Datacontext. I get error
When I'm trying get method from remote webservice it gives me error. My code
I have this piece of code: this.json.each(function(obj, index) { var li = new Element('li');
I like to get the index of the li element. The li elements are
Here is the updated code: private function myFillFunction(element:ChartItem, index:Number, item:Object, fieldName:String):IFill { var c:SolidColor
I have this query and I get error Operand should contain 1 column(s), whats
What is the best way to get error messages from a WF4 workflow back

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.