How can I call a function that outputs text files?
古いコメントを表示
I keep getting this error,
??? Error using ==> SECTOR
Too many output arguments.
for a function I created that outputs text files
The purpose of the function is that when the user types a corresponding number, MATLAB opens a file (fopen) which has been taken from a urlwrite function.
I am proceding the following way
function fid = SECTOR(user_entry1)
%
%
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz722.txt','Anegada_Passage_Southward.txt'); % URL from forecast webpage
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz710.txt','Atlantic_Waters.txt');
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz732.txt','Caribbean_Waters.txt');
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz715.txt','Coastal_Waters_Northern_Culebra_NOT_EasternPR.txt');
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz742.txt','Coastal_Waters_Northwestern.txt');
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz725.txt','Coastal_Waters_Southern.txt');
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz745.txt','Coastal_Waters_Southwestern.txt');
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz741.txt','Mona_Passage_Southward.txt');
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz712.txt','Coastal_Waters_Northern.txt');
urlwrite('http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/am/amz725.txt','Coastal_Waters_Southern_Vieques_Eastern.txt');
if user_entry1 == 1
fid=fopen('Anegada_Passage_Southward.txt');
elseif user_entry1 == 2
fid=fopen('Atlantic_Waters.txt');
elseif user_entry1 == 3
fid=fopen('Caribbean_Waters.txt');
elseif user_entry1 == 4
fid=fopen('Coastal_Waters_Northern_Culebra_NOT_EasternPR.txt');
elseif user_entry1 == 5
fid=fopen('Coastal_Waters_Northwestern.txt');
elseif user_entry1 == 6
fid=fopen('Coastal_Waters_Southern.txt');
elseif user_entry1 == 7
fid=fopen('Coastal_Waters_Southwestern.txt');
elseif user_entry1 == 8
fid=fopen('Mona_Passage_Southward.txt');
elseif user_entry1 == 9
fid=fopen('Coastal_Waters_Northern.txt');
elseif user_entry1 == 10
fid=fopen('Coastal_Waters_Southern_Vieques_Eastern.txt');
end
and the program file that calls the function goes like this,
fprintf('Choose your forecast region by typing corresponding number:\n 1. Anegada Passage\n 2. Atlantic Waters\n 3. Caribbean Waters\n 4. Coastal Waters Northern | Culebra\n 5. Coastal Waters Northwestern\n 6. Coastal Waters Southern\n 7. Coastal Waters Southwestern\n 8. Mona Passage Southward\n 9. Coastal Waters Northern\n 10. Coastal Waters Eastern | Vieques\n');
user_entry1=input('Input forecast: ');
fid = SECTOR(user_entry1);
The output of the function must be a text file that later would go as an input in the variable 'fid'.
Can you please help?
NOTE: I am trying to format the code starting with 'if user_entry1 == 1...', but MATLAB does not let me.
4 件のコメント
Walter Roberson
2012 年 9 月 30 日
Note that if the user enters something that is not 1, 2, 3, 4, 5, 6,7, 8, 9, or 10, then your code will not assign a value to "fid"
jjlivestrong
2012 年 9 月 30 日
Walter Roberson
2012 年 9 月 30 日
You should have code that assigns a value to "fid" even if the input is not one of those values. For example you could start with
fid = [];
jjlivestrong
2012 年 9 月 30 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Coastal Engineering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!