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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:59:48+00:00 2026-05-23T07:59:48+00:00

I’m wondering how I can copy (and maybe delete) handle objects within MATLAB. I

  • 0

I’m wondering how I can copy (and maybe delete) handle objects within MATLAB.

I am currently coding a solver for large systems of equations using MATLAB and an add-on called CPLEX. This solver essentially involves creating CPLEX handle objects and then solving them using a solve method as follows:

P = Cplex() %Create a Cplex object
%Code to specify the Cplex parameters
P.solve() %solve the Cplex object

In the code above, P is a MATLAB Handle Object that belongs to the Cplex() class. It stores a structure of matrices that relate to the factors of their equations.

The main issue that I am running is that I have to “solve” the same CPLEX object numerous times and I would like to do this in parallel, using a parfor loop. Unfortunately, the parfor loop in MATLAB requires transparency, since multiple threads cannot work on the same object.

I’ve thought of several ways around this: previously, I created and setup the Cplex() file within the parfor loop (this turns out to be slower than a single thread implementation); I also tried saving the object to disk and loading it up within the parfor loop (again too slow). Now I’d like to see if I could copy the object (either within the parfor loop, or outside of it). Unfortunately, however, there is no built-in “copy” function for Cplex objects and I would have to code something like that myself.

Essentially what I would like to do boils down to:

P = Cplex() %creates Cplex object
%Setup Cplex object

Q = cell(1,n) %create a container for Cplex objects

parfor 1:n

Q{i} = P.copy %create a copy of P and label it as Q{i}
Q{i}.solve()
Q{i} = [] %delete Cplex object (for memory purposes /preferable, but not necessary)

end
  • 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-23T07:59:49+00:00Added an answer on May 23, 2026 at 7:59 am

    I don’t have CPLEX and since I cannot replicate your code, please try the following suggestion and let me know if it works (or if you get an error, what the error is).

    Try defining Q outside of the parfor loop as

    Q=arrayfun(@(x)P.copy,1:n,'UniformOutput',false);
    

    This should create a cell as you had earlier and you can access it as Q{i} and should save you some time (because if you’re worried about memory issues that you delete each element after processing, then copying it might involve some time overhead too).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.