Why i get "Unexpected Matlab expression"?
이전 댓글 표시
function [Drcode, timer, lat, lon, u, v] = read_drifter_1('cc1.dat' , '0');
%
% usage [Drcode, timer, lat, lon, u, v] = read_drifter_1(filename, plotflag)
% this routine reads the data from the .dat files produced by the Android
% Drifter application, and provides the data.
%
fid = fopen('cc1.dat');
A = fgetl(fid);
timer=[];
lat=[];
lon=[];
u = [];
v = [];
while ~feof(fid),
A = fgetl(fid);
s = findstr(A,' ');
N = length(s);
Rlat = str2num(A(s(1)+1:s(2)-1));
Rlon = str2num(A(s(2)+1:s(3)-1));
Ryy = str2num(A(s(5)+1:s(6)-1));
Rmm = str2num(A(s(6)+1:s(7)-1));
Rdd = str2num(A(s(7)+1:s(8)-1));
Rhh = str2num(A(s(8)+1:s(9)-1));
Rmin = str2num(A(s(9)+1:s(10)-1));
Rsec = str2num(A(s(10)+1:length(A)));
Rtime = datenum(Ryy, Rmm, Rdd, Rhh, Rmin, Rsec);
lat = [lat; Rlat];
lon = [lon; Rlon];
timer = [timer; Rtime];
end
%
% Start a quality control regarding times
% Sort the data in increasing time
[timer2, Itime] = sort(timer,'ascend');
lat2 = lat(Itime);
lon2 = lon(Itime);
% remove the data taken at exactly the same time (double records)
dt = diff(timer2);
J = find(dt > 0);
timer = timer2(J+1);
lat = lat2(J+1);
lon = lon2(J+1);
% %
fclose(fid);
Drcode = [];
if plotflag ~=0,
figure
plot(lon2, lat2,'.')
hold on
plot(lon, lat, 'o')
end
return
Christos
댓글 수: 5
Christos Chatzilaou
2018년 6월 14일
Try to define your function like this
function [Drcode, timer, lat, lon, u, v] = read_drifter_1(mystring , plotflag) %no ''
%do something with your input
fid = fopen(mystring);
...
end
and then you can call it:
read_drifter('cc1.dat',0)
Christos Chatzilaou
2018년 6월 14일
Christos Chatzilaou
2018년 6월 14일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!