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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:27:11+00:00 2026-05-17T06:27:11+00:00

For my work I have to set up a project in Matlab, which is

  • 0

For my work I have to set up a project in Matlab, which is not my language of choice and I have some questions regarding efficiency.

I am currently dealing with a collection of points with several properties. Rather than putting all of these in separate arrays of equal length I would much prefer to make a single array of Point objects, using Matlab’s user defined classes. For example:

% Point.m
classmethod Point < handle
  properties
    x, y, prop1, prop2
  end
end

% script.m
... % define x(100), y(100), prop1(100), prop2(100)
points(100) = Point; % this seems to be the way to allocate an object vector
for i = 1:100
  points(i).x = x(i); % copy values into object
  points(i).y = y(i);
  points(i).prop1 = prop1(i);
  points(i).prop2 = prop2(i);
end

The reason that I prefer the above is both aesthetic (objects should be objects) and practical, as it allows me to easily create subsets of points without having to index several different arrays.

However I wonder if it is the most efficient way of doing things, considering that the set of points might grow quite large in the order of thousands or tens of thousands of points. My main questions are:

  1. For my understanding: how does Matlab store object arrays in memory? How does it handle varying object size dependent of prop1 being, for instance, a struct?
  2. How does this affect operations like [points.x], something that I would need to do quite often? Is this considered an efficient operation?
  3. Is there a better way to initialize the object array? The above loop construction seems highly inefficient.
  4. I suppose it should be possible to simulate object-like behaviour while storing properties more favourably, perhaps by overloading subsref. Would you recommend that?

Or to put things more general: what would be the optimal way of organizing my points?

Looking forward to your advice!

  • 1 1 Answer
  • 3 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-17T06:27:12+00:00Added an answer on May 17, 2026 at 6:27 am

    Not really answering your questions in order, but here’s some hopefully useful information:

    1. Objects are stored in memory in the same way as structures – each field is its own fully-fledged MATLAB array (mxArray to C-Mex programmers), so the size of each field can be independent.
    2. I would probably make something like a single PointList object with fields x, y, prop1, prop2. These fields would then be vectors of the appropriate length. This will almost certainly be more efficient than a list of Point objects. It will certainly take less memory.
    3. You should define accessor methods on PointList to ensure that your vectors are always the same lengths etc.
    4. If you really wanted to, you could have your PointList have a “capacity” that is larger than the number of elements currently stored in it – that way, you could avoid resizing x, y, … all the time
    5. In general, overloading subsref is not for the faint-hearted. Bear in mind that you also need to correctly overload at least numel, ndims, length, end and size too.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Query does not work when I have not set the ProcessorID in myComputer
I have a set of changes which work perfectly against a certain linux version,
I have a set of methods that do some utility work over SQL connection,
Hi I have an application which has a main project set to ver 3.5
I'm working on a validation project and I currently have it set up where
I have set up a .rvmrc file for my project, which simply looks like
At my current place of work we have a set way of going about
Since batch doesn't really have ints, I have to work around it with set
I have tried this but it doesn't work: tell application Preview set myfile to
The commandlink link2 does not have work after an ajax call is made 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.