Home > Blockchain >  matlab parfor unable to classify the variable
matlab parfor unable to classify the variable

Time:07-14

I'm trying to run a parfor loop to speed up everything. I've not completely understood the use of sliced variables.

What I want to do is to generate within the parfor a struct M storing all the figures with a getframe(fig) inside the function ThicknessVideoCreatorV2 needed to create a video. Within the loop the Mtemp struct with 'cdata' and 'colormap' variables is created and then assigned to the kk position of M.

iV=(iStart:iFinish) Divid-iStart;  
    istop=min(iV(end) iStart,nImag-iStart);
    
    M=[];
    
    parfor i=iStart:iStart 100%iStop
        kk=i-iStart 1;
        zz=iV(kk);
%         iV=i Divid-iStart;  
        
%         if iV iStart>nImag-iStart
%             
%             break
%     
%         else
        
             Mtemp=ThicknessVideoCreatorV2(LFradial(:,i), TfilmRadial(:,i),...
                 txt1{i}, txt2{i}, txt3{i},newIred{zz},fig, i, p1,p2,pl2,...
                 imgGraph, t1, t2,t3, pipeLength,limY_TBS);

             M(kk)=Mtemp;

    end
       

I get this error:

"Error: Unable to classify the variable 'M' in the body of the parfor-loop. For more information, see Parallel for Loops in MATLAB, "Solve Variable Classification Issues in parfor-Loops"."

How can I fix this and use parfor properly?

Thank you in advance

Riccardo

CodePudding user response:

The rules for "sliced" output variables in parfor basically come down to the constraint that you must assign based on the loop index. You are allowed to offset the loop index in the assignment, but your case doesn't fit into the current constraints (See "form of indexing" here). In this case, the simplest thing to do is swap i and kk

parfor kk = 1:100
    i = kk   iStart - 1;
    M(kk) = ...
end

Unfortunately, this will stop your inputs from being sliced - but that shouldn't stop the loop running.

  • Related