上文:
[ STK ](四) 使用 Matlab,获取卫星间可见性数据,分析得出可见性矩阵
[ STK ](六)使用 Matlab,获取卫星间距离数据
前言
- 在之前的文章中,我们建立了
STK
与Matlab
互联通信。 - 通过
Matlab
编码,获取分析得到卫星间可见性矩阵,距离矩阵 - 效果虽然实现了,但是代码的效率极低,影响实验。
- 本文中,对之前的代码进行了重写,提高了代码的执行效率。
实现思路
- 之前的实现思路:每秒钟获取一次可见性数据,分析导出可见性矩阵
- 本文的实现思路:一次性请求到所有的可见性数据,解析,每秒钟导出一个可见性矩阵
实现代码
- 代码目录
analysisRange.m :解析距离数据
analysisVisibility.m :解析可见性数据
close.m :关闭连接
getVisibility.m :获取所有可见性数据
getRange.m :获取所有距离数据
initConn.m :初始化连接
demo.m
% 注释 Ctrl + R/T
[conid,objNames] = initConn();
objNames(1) = '';
objNames(1) = '';
objNames(1) = '';
startTime = 0;
endTime = 600;
count = 24;
% 可见性
result = getVisibility(objNames,startTime,endTime,count);
% load('result.mat')
analysis(result,startTime,endTime,count);
% 距离
% load('range.mat')
result = getRange(objNames,count);
analysisRange(result,startTime,endTime,count);
close(conid);
initConn.m
% 初始化连接
function [conid,objNames] = initConn()
stkInit;
remMachine = stkDefaultHost;
conid = stkOpen(remMachine);
objNames = stkObjNames;
end
getVisibility.m
% 获取可见性
function [result] = getVisibility(objNames,startTime,endTime,count)
style = 'Access';
dt = 1;
result = {};
for i = 1:count
disp(strcat(num2str(i)))
for j = 1:count
if i ~= j
[secData, ~] =stkAccReport(char(objNames(int32(i))),char(objNames(int32(j))), style,startTime,endTime,dt);
result{i,j} = secData;
else
% 自己对自己设置为可见 1
result{i,j} = 1;
end
end
end
end
analysis.m
% 解析可见性数据
function [] = analysis(result,startTime,endTime,count)
for k = startTime:endTime
disp(strcat(num2str(k)))
visibility = zeros(count);
for i = 1:count
for j = 1:count
if iscell(result{i,j})
% 其他卫星
[~,tmp2] = size(result{i,j}{1,1});
if tmp2 == 4
% 存在可见性
[access,startTime,stopTime,~] = result{i,j}{1,1}.data;
[accessLength1,~] = size(access);
if accessLength1 == 1
% 全程可见
visibility(i,j) = 1;
else
% 检查是否在可见时间段内
for z = 1:accessLength1
if k >= startTime(z) && k <=stopTime(z)
% 存在可见性
visibility(i,j) = 1;
break;
end
end
end
else
% 不存在可见性
visibility(i,j) = 0;
end
else
% 对自身可见,存在可见性
visibility(i,j) = 1;
end
end
end
csvwrite(strcat('./data/visibility',num2str(k),'.csv'),visibility)
end
end
getRange.m
% 获取距离
function [result] = getRange(objNames,count)
style = 'AER';
result = {};
for i = 1:count
disp(strcat(num2str(i)))
for j = 1:count
if i ~= j
[rangeData, ~] =stkAccReport(char(objNames(int32(i))),char(objNames(int32(j))),style);
result{i,j} = rangeData;
else
% 自己与自己的距离为 0
result{i,j} = 0;
end
end
end
end
analysisRange.m
% 解析数据
function [] = analysisRange(result,startTime,endTime,count)
flag = 1;
for k = startTime:endTime
disp(strcat(num2str(k)))
range = zeros(count);
for i = 1:count
for j = 1:count
if iscell(result{i,j})
% 其他卫星
[~,tmp2] = size(result{i,j}{1,1});
if tmp2 == 4
% 存在距离
[time,azimuth,elevation,rangeTmp] = result{i,j}{1,1}.data;
% [rangeLength,~] = size(rangeTmp);
% if rangeLength == (endTime/60 + 1)
range(i,j) = rangeTmp(flag);
% end
else
% 不存在距离
range(i,j) = 0;
end
else
% 对自身距离为 0
range(i,j) = 0;
end
end
end
csvwrite(strcat('./data/range/range',num2str(k),'.csv'),range)
if rem(k,60) == 0
flag = flag + 1;
end
end
end
close.m
% 关闭连接
function []= close(conid)
stkClose(conid);
stkClose;
end