0
votes

I wished to write the below code in parallel:

    min=0;
    LB=[min1 min2]
    UB=[max1 max2]
    numvalues2=OpParam(2);
    for i =LB(1):step1:UB(1),
        for j =LB(2):step2:UB(2)
            acc=ComputeCbetaPerm( [i j],featureMatrix,labelMatrix);
            if(acc < max)
                acc=min;   
                values=[i j];
            end
        end
end

I Changed to the below to avoid the use of temporary variable max but still it gives an error of classification which I don't get.

    LB=[min1 min2]
    UB=[max1 max2]
    Result=cell(numvalues1,numvalues2,1);
    outervalues=LB(1):step1:UB(1);
    innervalues=LB(2):step2:UB(2); 
    for (i =1:numel(outervalues)),
        parfor (j =1:numel(innervalues)),
            acc=ComputeCbetaPerm( [outervalues(i) innervalues(j)],featureMatrix,labelMatrix);
            Result(i,:,1)={outervalues(i),innervalues(j),acc};
        end
    end

Asked also at http://in.mathworks.com/matlabcentral/answers/195799-classification-error-for-parfor.

EDIT:

Subscripted assignment dimension mismatch.

Caused by: Subscripted assignment dimension mismatch.

j

ans =

0.0000 + 1.0000i

1
Replace the parfor with a for and run the code. There is something wrong with the indices as Result(1,:,1) is written multiple times. - Daniel
Could you explain your code? Is it looking for maximum or minimum? For better readability, you could replace LB(1):((UB(1)-LB(1))/(numvalues1 -1)):UB(1) with linspace - Daniel
I don't much idea about how to solve the classification issue except a google search. Ideally with for it should be Result(i,j,1) - Abhishek Bhatia
@Daniel Check now. Sorry for readability issue - Abhishek Bhatia
@Daniel it's looking for minimum - Abhishek Bhatia

1 Answers

1
votes

The error is unrelated to parfor. You could replace parfor with for and you will receive the same error.

LB=[min1 min2]
UB=[max1 max2]
Result=cell(numvalues1,numvalues2,3);
outervalues=LB(1):step1:UB(1);
innervalues=LB(2):step2:UB(2); 
for i =1:numel(outervalues)
    parfor j =1:numel(innervalues)
        acc=ComputeCbetaPerm( [outervalues(i) innervalues(j)],featureMatrix,labelMatrix);
        Result(i,j,:)={outervalues(i),innervalues(j),acc};
    end
end

You are trying to put three values into the cell, but you allocated only space for one.