I have this piece of MATLAB code:
path(path,'./Classes');
locationID = 'Z8Ksof1rzm';
poolobj = gcp('nocreate');
if isempty(poolobj)
parpool(4)
else
%do nothing. we already have parpool running
end
myFiles = dir(strcat('./exportParse/exportLocation_', locationID));
MachineData = cell(length(myFiles)-2,1);
disp(myFiles)
parfor iFile =3:length(myFiles)
jsonFile = myFiles(iFile).name;
MachineData{iFile-2} = loadjson(strcat('./exportParse/exportLocation_', locationID,'/',jsonFile));
end
The script runs pretty well from the MATLAB desktop. I see no errors and I get all 4 processors working on the json parsing. At the end, I get MachineData filled with the desired information. All good.
The problem occurs when I call
matlabPath="/Applications/MATLAB_R2014b.app/bin/matlab -nodesktop -nosplash -r"
$matlabPath "run myScript.m"
where myScript.m is the file containing the code above. The script won't run again, it says this:
10x1 struct array with fields:
name
date
bytes
isdir
datenum
Error using readDataAprocam (line 17)
Improper index matrix reference.
Error in run (line 63)
evalin('caller', [script ';']);
as you can see, the line dis(myFiles) returns a valid struct array of files.
Line 17 is the line of the parfor command.
Note that on the shell and in MATLAB I'm located on the same path. I also shut down the parpool on the matlab desktop so the script running from the shell can claim it. there is no problem here as well.
What does Improper index matrix reference means on this context? Why does it run from the matlab desktop and not from the shell?
I'm running Mac OS X 10.11.3 and MATLAB 2014b.
forloop? I don't expect it to solve the issue, but it typically returns better error messages. - DanielA(1,2)element byA(3)(for A with size 2XN) in Matlab desktop but not from shell. - Crowleyfor, but not withparfor- otmezgerrun. My script doesn't have more than 20 lines. - otmezgerrun()command. Or You can nest it intotrycatch MEenvelope and display the error message inME. - Crowley