Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Par for

Subject: Par for

From: Saad

Date: 24 Aug, 2011 14:41:30

Message: 1 of 1

Dear All,

I have a function called " example1". I would like to evaluate it accross 9 grids until the ratio of the current value over the previous value is between 0.98 and 1.05. Please look the code below:


%%9 dimensional grid

grid1D=[-10:1:10; -10:1:10; -10:1:10; -10:1:10; -10:1:10; -10:1:10; -10:1:10; -10:1:10; -10:1:10];

x=[ 1, 2 3, 4, 5 ,6 ,7 ,8, 9];

arguments_2=num2cell(x);

for k=1:9
    
    
arguments_2{k}=grid1D(k,:);

end


arguments=num2cell(x);


 for k=1:8
     
     if (j >=0.98) & (j <=1.05)
     
            break
  
     else
         
         arguments{k}=arguments_2{k};
     
 for i=1:21
  
    arguments{k}=arguments_2{k}(i)

h(i,:)=example1(arguments{:})
 

 end

[j1, idx]=min(h)

  arguments{k}=grid1D(idx)

 
   for i=1:21
  
    arguments{k+1}=arguments_2{k+1}(i)

h(i,:)=example1(arguments{:})
 

 end

[j2, idx]=min(h);

  arguments{k+1}=grid1D(idx);
  
  
  j=j2/j1
   
  
     end
  
 end
  

The function "example1" takes approximately 12 hours to run thats why I would like to use parfor. Now I dont know in which loop it is the most efficient to place it in my code above? Any comment would be very helpful. Thanks a lot

Best
S
 

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us