How do I input this information in a cell array
1 view (last 30 days)
Show older comments
I have this text file and I want to store the fist 4 columns, starting from the third row in a variable called 'Time'
The text file is this,
http://www.ndbc.noaa.gov/data/realtime2/41053.txt
I am proceding the following way,
clc,clear all
fid = urlwrite('http://www.ndbc.noaa.gov/data/realtime2/41053.txt','SJ.txt'); % URL from CARICOOS
Data = SJ;
Time = Data{1,1};
The following is the function code,
function Data = SJ
fid = fopen( 'SJ.txt' );
Data = 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,
Error in ==> SJ at 3
end
??? Output argument "Data" (and maybe others) not assigned during call to
"C:\Users\User\Documents\MATLAB\CARICOOS\SJ.m>SJ".
Error in ==> SJ_F at 4
Data = SJ;
1 Comment
Walter Roberson
on 17 Feb 2013
To check: is your variable name assigned to by the textscan() exactly the same as the variable name on the left side of the "=" in your "function" line? It looks like it is in what you posted, but please confirm in your original source.
You will probably have to put a breakpoint in at the textscan line, and check the value of "fid" and step once to have the textscan() executed, then check the workspace to confirm that it was assigned.
Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!