% 读取文件路径
filePath = 'C:\Users\lx192\Desktop\八协解mavlink结果2.txt';
% 打开文件
fid = fopen(filePath, 'r');
% 初始化数据存储变量
latitude = [];
longitude = [];
altitude = [];
% 逐行读取文件内容
while ~feof(fid)
line = fgetl(fid);
% 解析每一行的数据
if startsWith(line, '飞行器纬度: ') && contains(line, ', 飞行器经度: ') && contains(line, ', 飞行器高度: ')
% 提取纬度、经度和高度数据
data = sscanf(line, '飞行器纬度: %f, 飞行器经度: %f, 飞行器高度: %fm');
latitude = [latitude; data(1)];
longitude = [longitude; data(2)];
altitude = [altitude; data(3)];
end
end
% 关闭文件
fclose(fid);
% 绘制三维可视化图
figure;
scatter3(latitude, longitude, altitude, 'filled');
xlabel('纬度');
ylabel('经度');
zlabel('高度 (米)');
title('飞行器轨迹三维可视化');
grid on;
% 设置坐标轴范围
xlim([34.75, 34.89]);
ylim([113.50, 113.58]);
using System;
using System.IO;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入要读取的文件路径:");
string filePath = Console.ReadLine();
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string outputPath = Path.Combine(desktopPath, "八协解mavlink结果2.txt");
FileStream fileStream = new FileStream(outputPath, FileMode.Create);
StreamWriter streamWriter = new StreamWriter(fileStream);
Console.SetOut(streamWriter);
FileStream fs = new FileStream(filePath, FileMode.Open);
MAVLink.MavlinkParse parse = new MAVLink.MavlinkParse();
while (fs.Position < fs.Length)
{
var msg = parse.ReadPacket(fs);
if (msg != null && msg.msgid == 33)
{
MAVLink.mavlink_global_position_int_t p = (MAVLink.mavlink_global_position_int_t)msg.data;
Console.WriteLine("飞行器纬度: {0}, 飞行器经度: {1}, 飞行器高度: {2}米", p.lat / 1E7, p.lon / 1E7, p.relative_alt / 1E3);
// 还可以执行其他操作...
}
}
fs.Close();
// 关闭文件流
streamWriter.Close();
fileStream.Close();
}
}
using System;
using System.IO;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入要读取的文件路径:");
string filePath = Console.ReadLine();
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string outputPath = Path.Combine(desktopPath, "八协解mavlink结果2.txt");
FileStream fileStream = new FileStream(outputPath, FileMode.Create);
StreamWriter streamWriter = new StreamWriter(fileStream);
Console.SetOut(streamWriter);
FileStream fs = new FileStream(filePath, FileMode.Open);
MAVLink.MavlinkParse parse = new MAVLink.MavlinkParse();
while (fs.Position < fs.Length)
{
var msg = parse.ReadPacket(fs);
if (msg != null && msg.msgid == 33)
{
MAVLink.mavlink_global_position_int_t p = (MAVLink.mavlink_global_position_int_t)msg.data;
Console.WriteLine("飞行器纬度: {0}, 飞行器经度: {1}, 飞行器高度: {2}米", p.lat / 1E7, p.lon / 1E7, p.relative_alt / 1E3);
// 还可以执行其他操作...
}
}
fs.Close();
// 关闭文件流
streamWriter.Close();
fileStream.Close();
}
}