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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:01:01+00:00 2026-06-18T06:01:01+00:00

I declared a 3-dimension matrix like this , and later in the iteration, I

  • 0

I declared a 3-dimension matrix like this , and later in the iteration, I need to dynamically expand the length of the third dimension.

Notice that currently, I only declare two dimensions but not the third dimension, so I will get an error like this:

Attempted to access bins(1,2,2); index out of bounds because
size(bins)=[2,22,1].

But the problem is, the Xk dimension is variable and I really cannot decide how it is needed. Is there anyway to declare a changeable matrix?

bins=zeros(2,size(Xtrain,2));
%Some for loop
    bins(Y,k,Xk)=bins(Y,k,Xk)+1;
%end loop
  • 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-06-18T06:01:02+00:00Added an answer on June 18, 2026 at 6:01 am

    You can use the end + k notation to dynamically expand the matrix as follows:

    A = zeros(10,10,10);
    size(A) %[10 10 10]
    Xk = 5;
    A(:,:,end+Xk) = 4;
    size(A) %[10 10 15]
    

    The size of A will have increased automatically and Matlab will automatically fill in-between values with zeros. However, resizing an array inside a loop is not a good way to program. You might want to rethink your method such that you aren’t doing this.

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

Sidebar

Related Questions

I declared a multidimensional array in C, like so: int arr[4][2]; int length =
I declared a 2-dimensional array like this: char *array[][3] = { {a, b, c},
i need to declare an array with user-defined dimension. This array is inside a
I have an abstract class A that define abstract methods. This means that, for
I have declared adMob on manifest like <activity android:name=com.google.ads.AdActivity android:configChanges=keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize /> It is resized
I have a stored procedure that dynamically generates MERGE TSQL statements to handle SCD
I'm trying to do the SQL equivalent of this in Oracle. Basically, I need
I want to create one button/layout object dynamically from the object that exist on
I've got a javascript include that's declared in the head of the frameset of
I have written the following stored procedure that uses a Date Dimension table to

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.