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

 采纳的回答

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 个评论

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 = ' ';
...

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Design and Simulate SerDes Systems 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by