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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:46:02+00:00 2026-06-11T02:46:02+00:00

I have a handle class: classdef A<handle properties a; end methods function obj =

  • 0

I have a handle class:

classdef A<handle


    properties
        a;
    end

    methods
        function obj = A(a)
            obj.a=a;
        end
    end
end

And I have a cell array of A objects:

arr={};
for i=1:3
    arr{i}=A(i);
end

What I would like to do is pass that cell array to a parfor loop so that each object’s value will change:

parfor i=1:3
    arr{i}.a=i*5;
end

However, this code does not change arr at all. Indeed, here it states that

Changes made to handle classes on the workers during loop iterations are not automatically propagated to the client.

How can I overcome this?

  • 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-11T02:46:03+00:00Added an answer on June 11, 2026 at 2:46 am

    An interesting question; I actually never encountered this problem. It’s always good to know everything about parfor limitations, so I did some googlin’ and came up with this:

    I have received an answer to this issue from technical support.
    Apparently the Mathworks regard it as a ‘feature’ that changes to
    objects are not returned – though I can’t see that it’s a very useful
    feature. Anyway, the way to get modified class properties returned
    from a parfor loop is to make an explicit change which can be
    recognised by parfor. Here are two examples which work for the above
    example object:

    parfor n = 1:num
        exArray(n).data = n:n+5;
    end
    

    or

    parfor n = 1:num
        temp = exArray(n);
        setData(temp,n:n+5);
        exArray(n) = temp;
    end
    

    Actually, if you change any object property it also seems to work. So
    for example this also works, if there is a second property data2 which
    is set explicitly, both data and data2 are correctly returned:

      parfor n = 1:num
          setData(exArray(n),n:n+5);
          exArray(n).data2 = n:n+5;
      end
    

    Where the example object is given by

    classdef Example < handle
    
        properties
            data
        end
    
        methods
            function obj = Example(data)
                obj.data = data;
            end
    
            function setData(obj,data)
                obj.data = data;
            end
    
            function data = getData(obj)
                data = obj.data;
            end
        end
    end
    

    and the array is initialized simply as

    % Initialise array of objects
    for n = 1:num
        exArray(n) = Example(zeros(1,6));
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let we have one abstract class: classdef ACalculation < handle methods (Abstract) [result] =
Suppose I have the following class: classdef myClass < handle properties A = [10
I have a class that implements properties in a specific way, to handle some
This is what I have and it works: $(function(){ $('.slide-out-div').tabSlideOut({ tabHandle: '.handle', //class of
Say I have a 1x2 object array of a handle class with a method
I would like my AOP advice to have a handle to the currently executing
I have an abstract Handle<T> class that contains references an objects of type T.
I have written a custom class to handle database queries to a remote and
I have a class I'm using to handle all my DB interaction. Basically when
I have written a class that will handle internal logging in my application. Now

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.