上文
[ STK ](十)【算法优化】与 Matlab 互联通信,获取卫星间可见性数据,计算可见性矩阵,距离矩阵
前言
- 测试中发现有之前没考虑到的情况,做了修改
- 结果矩阵的上三角与下三角的结果一样,就只获取一次数据吧
- 懒得写注释了,将就看吧
实现代码
- 代码目录
main
% 注释与取消注释快捷键 Ctrl + R/T
% 获取连接id,场景内所有对象的全路径
[conid,objNames] = initConn();
% 删除场景名称
objNames(1) = '';
% 设置开始时间
startTime = 0;
% 设置结束时间
endTime = 2000;
% 设置参与计算的对象总数
count = 71;
% 获取可见性数据
result = getVisibility(objNames,startTime,endTime,count);
% 加载数据集
% load('result.mat')
% 解析可见性数据,保存为.csv 文件
analysisVisibility(result,startTime,endTime,count);
step = 99;
% 步长 100
for i = startTime:100:endTime
if((i + step) > endTime)
break
end
% 获取距离数据
result = getRange(objNames,i,i + step,count);
% 解析距离数据
analysisRange(result,i,i + step,count);
end
% 关闭连接
close(conid);
% 初始化连接
function [conid,objNames] = initConn()
stkInit;
remMachine = stkDefaultHost;
conid = stkOpen(remMachine);
objNames = stkObjNames;
end
% 获取可见性数据
function [result] = getVisibility(objNames,startTime,endTime,count)
% 设置报表样式
style = 'Access';
% 设置间隔时间(持续时间)
dt = 1;
% 保存结果集
result = {};
for i = 1:count
% 打印执行进度
disp(strcat(num2str(i)))
for j = i:count
if i ~= j
[secData, ~] =stkAccReport(char(objNames(int32(i))),char(objNames(int32(j))), style,startTime,endTime,dt);
result{i,j} = secData;
result{j,i} = secData;
else
% 设置自己与自己的可见性 1
result{i,j} = 1;
end
end
end
end
% 获取距离
function [result] = getRange(objNames,startTime,endTime,count)
style = 'AER';
result = {};
dt = 1;
for i = 1:count
disp(['i = ',strcat(num2str(i))])
for j = i:count
disp(['j = ',strcat(num2str(j))])
if i ~= j
try
rangeData = stkAccReport(char(objNames(int32(i))),char(objNames(int32(j))),style,startTime,endTime,1);
result{i,j} = rangeData;
result{j,i} = rangeData;
catch exception
warning('stkAccReport err:');
end
else
% 自己与自己的距离为 0
result{i,j} = 0;
end
end
end
end
% 解析可见性数据
function [] = analysisVisibility(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);
% 检查是否在可见时间段内
for z = 1:accessLength1
if k >= startTime(z) && k <=stopTime(z)
% 存在可见性
visibility(i,j) = 1;
break;
end
end
else
% 不存在可见性
visibility(i,j) = 0;
end
else
% 对自身可见,存在可见性
visibility(i,j) = 1;
end
end
end
csvwrite(strcat('./data/vis/visibility',num2str(k),'.csv'),visibility)
end
end
% 解析数据
function [] = analysisRange(result,startTime,endTime,count)
flag = 1;
for k = startTime:endTime
disp(strcat('k = ',num2str(k)))
range = zeros(count);
for i = 1:count
disp(strcat('i = ',num2str(i)))
for j = 1:count
disp(strcat('j = ',num2str(j)))
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;
% 如果取不到对应秒数的距离,说明该时刻不存在距离
% time ,rangeTmp 可能为空
try
if k == floor(time(flag))
range(i,j) = rangeTmp(flag);
flag = flag + 1;
else
range(i,j) = -1;
end
catch exception
range(i,j) = -1;
end
else
% 不存在距离
range(i,j) = -1;
end
else
% 对自身距离为 0
range(i,j) = 0;
end
end
end
csvwrite(strcat('./data/range/range',num2str(k),'.csv'),range)
end
end
% 关闭连接
function []= close(conid)
stkClose(conid);
stkClose;
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)