MATLAB: Error: Attempt to execute script as function/no return for “which” command.

functionscript

This is a very common problem, but thus far I have not been able to fix my error using the Matlab troubleshooting solutions. I'm kind of new to matlab so forgive me for being green if it's something obvious I just don't see. The script file I'm trying to modify is called waxsimport.m:
waxsexposures = waxsimport(waxs_exposures_2015.par, 1, inf)
%%Initialize variables.
delimiter = ' ';
if nargin<=2
startRow = 1;
endRow = inf;
end
%%Read columns of data as strings:
formatSpec = '%s%s%s%s%s ... %s%s%[^\n\r]';
%%Open the text file.
fileID = fopen('waxs_exposures_2015.par', '/r/');
end
(that's not the entire thing) returns:
Attempt to execute SCRIPT waxsimport as a function: C:\Users\Owner\Documents\…\waxsimport.m
Error in waxsimport (line 1) waxsexposures = waxsimport('waxs_exposures_2015.par', 1, inf)
I read through a few q&a's and I have deleted all other files involving the phrase "waxsimport" from the path, so it's not looking for the wrong script.
Also, I tried the command
>> which -all waxsimport
'‹waxsimport›' not found.
>> which -all waxsimport.m
'‹waxsimport.m›' not found.
So I double checked and waxsimport.m was in the path. The goal is to import data from a .par into a matrix in the workspace.

Best Answer

No, the file needs to start with
function waxsexposures = waxsimport(waxs_exposures_2015, startRow, endRow)
but you need to invoke it from outside the function, and the invocation in that other routine would look like
waxsexposures = waxsimport('waxs_exposures_2015.par', 1, inf)
Or is your intent to provide "default" values if the user did not specify any inputs? If that was what you were trying to do then you would use a different form: you would use
function waxsexposures = waxsimport(waxs_exposures_2015, startRow, endRow)
if nargin < 1
waxs_exposures_2015 = 'waxs_exposures_2015.par';
end
if nargin < 2
startRow = 1;
end
if nargin < 3
endRow = inf;
end
delimiter = ' ';
%%Read columns of data as strings:
formatSpec = '%s%s%s%s%s ... %s%s%[^\n\r]';
%%Open the text file.
fileID = fopen(waxs_exposures_2015, 'rt'); %changed
...
fclose(fileID);