How do I input this information in a cell array
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2013-2-17
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!