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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:44:34+00:00 2026-06-01T20:44:34+00:00

Currently I have a parfor loop making calculations on a struct in MATLAB. While

  • 0

Currently I have a parfor loop making calculations on a struct in MATLAB. While my code is a bit long to post, it can be emulated using the following example:

a.test = [1 2 3];
result = [];

parfor i = 1:3
  c = a;
  c.test(2) = round( rand() );

  if c.test(2) == 1
     %# Store c in result
  end
end

disp(result.test) %# Should show [1 1 3]

a (and consequently c) is a very large structure, so storing every iteration is not feasible for me (due to memory constraints).

Ideally I would like to be able to store c straight to a variable that I initialise before the parfor loop. Looking at MATLAB’s Example: Using a Custom Reduction Function, I can see it is possible to store a given iteration variable (without having to store every single iteration) yet I do not fully understand their method. I’m baffled by how their function produces 2 separate output variables (seemingly) while the function only defines one output variable.

I am sure this is a very common problem but so far none of my searches have yielded any valid results.

Any help would be much appreciated.

  • 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-01T20:44:36+00:00Added an answer on June 1, 2026 at 8:44 pm

    The example you link to is not quite what you want. However, it is possible to store only the “good” results. Here’s a simple example:

    A=zeros(0,2); %# initialize A with no rows, two columns
    parfor i=1:6
       tmp = rand(1); %# create some result
       if tmp > 0.5 %# store only part of the results
          A = [A;[tmp,i]]; %# store also the iteration number, in case it matters
       end
    end
    >> A
    
    A =
    
        0.6497    2.0000
        0.5052    4.0000
        0.9993    5.0000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently have this code defining getter/setter for an object's selectedID property. The object is
I currently have this in my code tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(updateLeftLabel:)]; which
Currently I have the following code for a project that represents some probability trees
I currently have the following code that retrieves data from the database and then
I currently have the following: (defun my-hide-code () (interactive) (set-selective-display 2)) (defvar my-keys-minor-mode-map (make-keymap)
I currently have a game loop that fires off about 20 times per second
I currently have a Rails app in which users of different ranks can upload
Currently have installed Windows 7 Home premium, im just wondering if i can install
I currently have the below code, but obviously I am not that skilled on
Currently have password protection on my main and sub directories, however I'd like 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.