MATLAB parfor error: function or variable?

FliegenderZirkus

The following code:

matlabpool('open','local',2)

parfor i=1:5
    proc = System.Diagnostics.Process;
end

results in an error:

Error: MATLAB cannot determine whether "System" refers to a function or variable.

However, when I execute the parfor loop again (after the error), it runs through! I found a couple of similar questions, but I wasn't able to implement the suggested solutions.

MATLAB parfor - cannot determine whether "ModelUtil" refers to a function or variable?

MATLAB using parfor (parallel computing toolbox) and custom packages with +

I can't wrap my mind around why the loop runs the second time. If I then call

matlabpool close

and execute the whole script again, the error appears once again. So it only happens the first time after the pool was initiated. Any ideas?

Hoki

This is because any variable or function you use in a parfor loop must be defined explicitly in the code at parsing time. If there is any ambiguity, Matlab opt to throw an error rather than messing up by assuming.

Just define an anonymous function that create the object you want before the parfor loop, then you can use it as will within the parfor loop.

This run fine on my machine (Matlab R2013a):

getSystemProcess = @() System.Diagnostics.Process ;
parfor i=1:5
    proc = getSystemProcess();
end

Read this Matlab chapter for more informations on how the variable/function names are interpreted in a parfor loop: Unambiguous Variable Names

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MATLAB parfor error "The variable in a parfor cannot be classified."

From Dev

Error using parfor in matlab // The variable in a parfor cannot be classified

From Dev

"the variable in a parfor cannot be classified." error in Matlab

From Dev

parfor with Matlab "the variable __ in a parfor cannot be classified"

From Dev

Matlab Parfor Variable cannot be Classified

From Dev

Matlab Parfor Variable cannot be Classified

From Dev

Access variable in nested parfor loop in MATLAB

From Dev

parfor in matlab. sliced variable and nested loop

From Dev

Matlab parfor nested loop variable access

From Dev

How to use a variable outside a PARFOR loop in MATLAB?

From Dev

parfor in matlab. sliced variable and nested loop

From Dev

Matlab parfor nested loop variable access

From Dev

Getting error in parfor but not in for-loop in matlab

From Dev

undefined function or variable error in MATLAB

From Dev

undefined function or variable error in MATLAB

From Dev

Using Matlab Parfor with 'Eval'

From Dev

matlab parfor not working

From Dev

Using spmd or parfor in Matlab

From Dev

Using Matlab Parfor with 'Eval'

From Dev

Matlab parfor slice correctly

From Dev

Compiling error due to variable size Matrix in simulink (matlab function block)

From Dev

parfor in Matlab using HPC is slower?

From Dev

Simple example of MATLAB's parfor

From Dev

Undefined function or variable Matlab

From Dev

Undefined function or variable Matlab

From Dev

matlab function variable definition

From Dev

MATLAB bug? "Undefined function or variable" error when using same name for function and variable

From Dev

MATLAB bug? "Undefined function or variable" error when using same name for function and variable

From Dev

Nested function error in matlab

Related Related

  1. 1

    MATLAB parfor error "The variable in a parfor cannot be classified."

  2. 2

    Error using parfor in matlab // The variable in a parfor cannot be classified

  3. 3

    "the variable in a parfor cannot be classified." error in Matlab

  4. 4

    parfor with Matlab "the variable __ in a parfor cannot be classified"

  5. 5

    Matlab Parfor Variable cannot be Classified

  6. 6

    Matlab Parfor Variable cannot be Classified

  7. 7

    Access variable in nested parfor loop in MATLAB

  8. 8

    parfor in matlab. sliced variable and nested loop

  9. 9

    Matlab parfor nested loop variable access

  10. 10

    How to use a variable outside a PARFOR loop in MATLAB?

  11. 11

    parfor in matlab. sliced variable and nested loop

  12. 12

    Matlab parfor nested loop variable access

  13. 13

    Getting error in parfor but not in for-loop in matlab

  14. 14

    undefined function or variable error in MATLAB

  15. 15

    undefined function or variable error in MATLAB

  16. 16

    Using Matlab Parfor with 'Eval'

  17. 17

    matlab parfor not working

  18. 18

    Using spmd or parfor in Matlab

  19. 19

    Using Matlab Parfor with 'Eval'

  20. 20

    Matlab parfor slice correctly

  21. 21

    Compiling error due to variable size Matrix in simulink (matlab function block)

  22. 22

    parfor in Matlab using HPC is slower?

  23. 23

    Simple example of MATLAB's parfor

  24. 24

    Undefined function or variable Matlab

  25. 25

    Undefined function or variable Matlab

  26. 26

    matlab function variable definition

  27. 27

    MATLAB bug? "Undefined function or variable" error when using same name for function and variable

  28. 28

    MATLAB bug? "Undefined function or variable" error when using same name for function and variable

  29. 29

    Nested function error in matlab

HotTag

Archive