Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparency Error when using table in parfor loop

I am trying to use a table within a parfor loop in MATLAB. This gives me "Transparency violation error. See Parallel Computing Toolbox about transparency" I'm trying to build this table so I can make a prediction using a trained classifier from the MATLAB classification learner app (trainedClassifier.prefictFcn(T))...so either I need to build a table within the parfor loop or need some alternative to a table that I can still feed into the classifier.

parfor i=1:100
    acheck=1;
    bcheck=2;
    ccheck=3;
    T=table(acheck,bcheck,ccheck);
end
like image 353
user3470496 Avatar asked Mar 14 '26 04:03

user3470496


1 Answers

This solution works for your particular problem:

parfor i=1:100
    acheck=1;
    bcheck=2;
    ccheck=3;
    T(i,:)=table([acheck,bcheck,ccheck]);
end

Note that in your original program you just overwrite existing values and end up with a one row table. I assumed that that was not intended. Actually, that would be the outcome of a for.

Also, since this is a parfor and T is created inside the loop (as well as acheck, etc.) using just T creates nothing at all. The variable is a temporary one, visible to each process locally and destroyed in global scope (more can be found here).

To fix both overwriting and accessibility the program assigns the each set of variables to each row of T. If square brackets are omitted, the program throws a transparency error. Unfortunately, I do not know why is that but it may be that the operations done by the table data-structure cause that. Maybe someone else will know the answer, for now this seem to solve your problem though.

like image 102
atru Avatar answered Mar 16 '26 11:03

atru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!