using findstr to find what you are looking for
Show older comments
Here is a function that is suppose to take a datetime, reformat it in a way where it can search for a date on the following webiste, https://www.celestrak.com/SpaceData/EOP-Last5Years.txt. I am getting an error 'Error using findstr
Conversion to double from datetime is not possible.' and do not know how to fix it.
Here is the script:
datestr = datetime('now');
%startdatestr = datestr(get(handles.startedit,'string'),'yyyy mm dd');
startdatestr = datetime (('now'), 'Format','yyyy MM dd')
internet = inputdlg('Are you connected to the internet? (y/n)','Connectivity');
if(strcmp(internet,'y'))
eopdata = urlread('https://www.celestrak.com/SpaceData/EOP-Last5Years.txt');
ind = findstr(eopdata,startdatestr);
xp = str2num(eopdata(ind+18:ind+26))*convrt;
yp = str2num(eopdata(ind+28:ind+36))*convrt;
dut1 = str2num(eopdata(ind+38:ind+47));
lod = str2num(eopdata(ind+49:ind+58));
% dPsi = str2num(eopdata(ind+60:ind+68));
% dEpsilon = str2num(eopdata(ind+70:ind+78));
% dx = str2num(eopdata(ind+80:ind+88));
% dy = str2num(eopdata(ind+90:ind+98));
dat = str2num(eopdata(ind+100:ind+102));
else
localeopfile = inputdlg('Do you have the latest EOP file from https://www.celestrak.com/SpaceData/EOP-Last5Years.txt (y/n)','EOP File');
if(strcmp(localeopfile,'y'))
[filename,pathname] = uigetfile('*.txt', 'Select an EOP file');
if(isempty(filename))
return;
end
fid = fopen(fullfile(pathname,filename));
datastartstr = 'BEGIN OBSERVED';
while 1
tline = fgetl(fid);
if(strcmp(datastartstr,tline))
break;
end
end
while 1
tline = fgetl(fid);
if(~isempty(tline))
if(strcmp(startdatestr,tline(1:10)))
break;
end
end
end
eopdata = tline;
xp = str2num(eopdata(18:26))*convrt;
yp = str2num(eopdata(28:36))*convrt;
dut1 = str2num(eopdata(38:47));
lod = str2num(eopdata(49:58));
% dPsi = str2num(eopdata(60:68));
% dEpsilon = str2num(eopdata(70:78));
% dx = str2num(eopdata(80:88));
% dy = str2num(eopdata(90:98));
dat = str2num(eopdata(100:102));
else
xp=0;
yp=0;
lod=0;
dut1=0;
dat=0;
msgbox('EOP data set to zeros. EOP file can be downloaded from http://celestrak.com/SpaceData');
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Tables 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!