I've created a GUI using a figure and several uicontrol objects (checkboxes, pushbuttons, radios, edits,..). The idea is to use this as a dashboard to run a user-decided subset of functions. When a certain button is pushed, it gets information from the values of GUI checkboxes and radio buttons and uses this information as the input to a function called myFunction. myFunction then has a switch format, which operates based on some of the values input from the GUI.
For one of the switch values, I'd like to run a function, myFunction2, which is an I/O function (it looks like output(loopcount)=myFunction2(filename, otherinput(loopcount)) ). myFunction2 navigates to a data file based on an input to the function, filename. Filename contains the complete path to the data file. I want to run this I/O function several times on the same data file with the "otherinput" varying for each execution.
This runs successfully when I run it as a for loop:
function myFunction(gui_input)
switch gui_input
case Mode_1
for loopcount = 1:1000
output(loopcount) = myFunction2(filename, otherinput(loopcount))
end
end
end
However, when I try to run this as a parfor loop (Start parallel pool from main Matlab window before I start up the GUI) and simply change "for" to "parfor" I get this error:
Error using myFunction>(parfor body) (line 29)
An UndefinedFunction error was thrown on the workers for 'filename'. This might be because the file containing 'filename' is not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to be attached. See the documentation for 'parallel.Pool/addAttachedFiles' for more details.
Error in myFunction (line 28)
parfor loopcount = 1:10
Error in gui_function/Runanalysis_callback (line 154)
myFunction(gui_input)
Caused by:
Undefined function or variable 'filename'.
Error while evaluating uicontrol Callback
Unfortunately I'm pretty new to both GUI's and parfor loops. Can anyone point me in the right direction?
Thanks, I would really appreciate it!