Why do I keep getting this error on function

1 次查看(过去 30 天)
I am trying to generate a function that creates an output of very extensive wave forecast data divided in cell array.
The code goes like this,
clc,clear all
fid = urlwrite('http://www.ndbc.noaa.gov/data/realtime2/41115.spec','Rincon.txt'); % URL from CARICOOS
cac = cssm(fid)
The function goes like this,
function cac = cssm()
fid = fopen( 'Rincon.txt' );
cac = textscan( fid, '%d%d%d%d%d%f%f%f%f%f%s%s%s%f%f' ...
, 'Delimiter' , ' ' ...
, 'CollectOutput' , true ...
, 'HeaderLines' , 2 ...
, 'MultipleDelimsAsOne' , true ...
, 'Whitespace' , '' ...
);
fclose( fid );
end
I keep getting this error and don't know how to fix it, could you please help?
??? Error using ==> cssm
Too many input arguments.
Error in ==> ult1 at 4
cac = cssm(fid)

采纳的回答

Wayne King
Wayne King 2012-12-18
编辑:Wayne King 2012-12-18
You need to define your function with the input argument
function cac = cssm(fid)
then pass the function the file identifier, don't put it inside your function.
Why do you have code like this:
fid = urlwrite('http://www.ndbc.noaa.gov/data/realtime2/41115.spec','Rincon.txt'); % URL from CARICOOS
cac = cssm(fid)
and then on line two of your function, you have
fid = fopen('Rincon.txt');
??
Either declare the function with NO input arguments
function cac = cssm
and do everything internally, or pass, the function the fid argument and get the file identifier before you call the function.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by