Parse error when using importfile?

I'm trying to import data from a .csv file (either one) into a matrix. I'm getting a "parse error" at line 1:
function waxsexposures = waxsimport('waxs_exposures_2015', 1, inf)
This is of the form
waxsexposures = importfile('waxs_exposures.par', startRow, endRow)
I've tried the following:
waxsexposures = waximport('waxs_exposures_2015')
---return--->Not enough input arguments.
waxsexposures = waximport('waxs_exposures_2015.par')
---return--->Unexpected MATLAB operator.
function waxsexposures = waxsimport(waxs_exposures_2015, startRow, endRow)
%%Initialize variables.
delimiter = ' ';
if nargin<=2
startRow = 1;
endRow = inf;
end

 Accepted Answer

Walter Roberson
Walter Roberson on 30 Jan 2016
Edited: Walter Roberson on 30 Jan 2016
Leave off the "function" when you invoke. You should use the code like you have at the bottom but to test it you should be using
waxsexposures = waxsimport('waxs_exposures_2015', 1, inf)
at the command line, without the word "function".

2 Comments

Thank you. Now it's returning Attempt to execute SCRIPT waxsimport as a function: C:\Users\...\waxsimport.m
Error in waxsimport (line 1) waxsexposures = waxsimport('waxs_exposures_2015.par', 1, inf)
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', 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';
end
if nargin < 2
startRow = 1;
end
if nargin < 3
endRow = inf;
end
delimiter = ' ';
...

Sign in to comment.

More Answers (0)

Categories

Find more on Design and Simulate SerDes Systems in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!