How to index into temporary variables within parfor
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    MJ
 el 28 de Oct. de 2020
  
    
    
    
    
    Respondida: Rashed Mohammed
    
 el 5 de Nov. de 2020
            Hi all,
Forgive me if this has been asked many times before. I've seen a few similar questions but nothing that fully helped me. I am trying to use a for loop to intialize the values at the indeces of a temporary variable within a larger parfor loop. The following is a "toy problem" to illustrate what I am talking about:
parfor i = 1:20
    for j = 1:10
        mymat(j,1) = j;
    end
end
MATLAB tells me "The parfor loop cannot be run due to the way "mymat" is used." I don't know why matmat is used improperly, since it is a temporary variable that, based on my understanding, exists separately for each independent iteration of the loop. Note that I will never try to access mymat outside of each individual parfor loop, nor does one iteration of the loop need any knowledge of the information in another iteration's mymat variable. 
I realize that this example looks a little silly because can be done without the nested for loop or parfor. I am just using it to illustrate the basic concept of what I am trying to do for my particular application. It is absolutely necessary that my final application has this sort of structure--is this possible somehow? Thanks!
0 comentarios
Respuesta aceptada
  Rashed Mohammed
    
 el 5 de Nov. de 2020
        Hi MJ
Please refer to the Sliced Variables Documentation for correctly indexing variables in a parfor loop
Hope this helps !
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!