Filter löschen
Filter löschen

Why do I keep getting this error on function

1 Ansicht (letzte 30 Tage)
Juan Rosado
Juan Rosado am 18 Dez. 2012
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)

Akzeptierte Antwort

Wayne King
Wayne King am 18 Dez. 2012
Bearbeitet: Wayne King am 18 Dez. 2012
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.

Weitere Antworten (0)

Kategorien

Mehr zu Standard File Formats finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by