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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:33:29+00:00 2026-05-26T09:33:29+00:00

I have a handle-based class that I need to create a vector of. An

  • 0

I have a handle-based class that I need to create a vector of. An easy method of doing this is to dynamically construct the vector in a for loop, but this causes mlint to complain about the changing vector size.

classdef HandleClass < handle
    ...
end

...

for i = 1:10
    foo(i) = HandleClass();
end

I’m suspicious of the resource-hit required to use this method to allocate large arrays of complicated objects.

A comment in a previous thread described a useful method to create a vector using the repmat function. However, @gnovice warned that doing that would create a vector of handles pointing to the same object. I have tested this and it appears to be the case.

Is there a trick that allows a vector of unique handle objects to be pre-allocated without the use of a for loop?


Solution Summary

The solution presented by SCFrench correctly allocates the memory for the creation of a vector of objects. Other solutions will create the vector, but will not allocate the memory.

foo(10) = HandleClass();
  • 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-26T09:33:29+00:00Added an answer on May 26, 2026 at 9:33 am
    foo(10) = HandleClass();
    

    This will default fill foo(1) through foo(9).

    Note that this only works if HandleClass’s constructor works with no input arguments (that is, it can be default-constructed).

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

Sidebar

Related Questions

I have to dynamically instantiate certain class based on runtime configuration. So, I need
I have a class that handles events from a WinForms control. Based on what
In my Java course I have to create a GUI class that interacts with
I have a resource handler that is Response.WriteFile(fileName) based on a parameter passed through
I have a UIViewController subclass that I am trying to have handle the shake
I have a PHP application that will on occasion have to handle URLs where
I have a file handle to a serial (COM) port. I need to read
I have a master class: A with a constructor that takes an optional login
So this is probably an easy thing that I'm trying to do but I'm
Maybe that's not exactly the solution i need, but this is what i want

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.