Why do I keep getting this error on function

1 回表示 (過去 30 日間)
Juan Rosado
Juan Rosado 2012 年 12 月 18 日
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.
  1 件のコメント
Juan Rosado
Juan Rosado 2012 年 12 月 18 日
Thank you
:)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-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