% 连接STK
remMachine = 'localhost';
conid = stkOpen(remMachine);
% 检查当前是否有打开的场景
scen_open = stkValidScen;
if scen_open == 1
rtn = questdlg('Close the current scenario?');
if ~strcmp(rtn, 'Yes')
stkClose(conid);
return;
else
stkUnload('/*');
end
end
% 创建新场景
disp('Create a new scenario: SatelliteFormation');
stkNewObj('Scenario', '', 'SatelliteFormation');
stkNewObj('*/', 'Satellite', 'Chief');
% 设置场景时间段
disp('Set scenario time period');
stkSetTimePeriod('1 May 2007 00:00:00.00', '2 May 2007 00:00:00.00', 'GREGUTC');
stkSetEpoch('1 May 2007 00:00:00.00', 'GREGUTC');
stkSyncEpoch;
rtn = stkConnect(conid, 'Animate', 'Scenario/SatelliteFormation', 'SetValues "1 May 2007 00:00:00.00" 60 0.1');
rtn = stkConnect(conid, 'Animate', 'Scenario/SatelliteFormation', 'Reset');
% TLE文件路径列表
tleFiles = {
'path/to/tle1.txt',
'path/to/tle2.txt',
'path/to/tle3.txt'
};
% 导入每个TLE文件
for i = 1:length(tleFiles)
tleFile = tleFiles{i};
% 打开TLE文件并读取内容
fid = fopen(tleFile, 'r');
tleLines = textscan(fid, '%s', 'Delimiter', '\n');
fclose(fid);
% 提取TLE数据
tleLines = tleLines{1};
line1 = tleLines{2}; % 第一行TLE数据
line2 = tleLines{3}; % 第二行TLE数据
% 创建卫星对象
satelliteName = sprintf('Satellite_%d', i);
stkNewObj('*/', 'Satellite', satelliteName);
% 设置卫星的TLE数据
rtn = stkConnect(conid, 'SetState', ['*/Satellite/', satelliteName], ['TLE ' line1 ' ' line2]);
end
disp('TLE files imported successfully.');
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.