필터 지우기
필터 지우기

How do I input this information in a cell array

조회 수: 1 (최근 30일)
Juan Rosado
Juan Rosado 2013년 2월 17일
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
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 CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by