阅读GNSS软件接收机matlab代码(一)
一、格式化,初始化
%% Clean up the environment first =========================================
clear; close all; clc;
format ('compact');
format ('long', 'g');
%--- Include folders with functions ---------------------------------------
addpath include % The software receiver functions
addpath geoFunctions % Position calculation related functions
代码开始时初始化,clear清除工作区内所有变量,close all 关闭所有图窗,clc清理命令行窗口。
format是调整显示格式
format (‘compact’); compact是紧凑的意思,使显示紧凑些,举例如下。
A = 5.123456789;
for k = 1:10
disp(A)
A = A*10;
end
结果
经过 format compact 后显示结果不空行了
addpath
addpath include之后,可以直接调用include文件夹下的函数了,这样可以使工程文件夹显得条理有层次。
二、参数初始化
%% Initialize constants, settings =========================================
settings = initSettings();
把所有的参数放在一个结构体函数中
aa=aaa();
子函数:
function aaa1=aaa();
aaa1.a=1;
aaa1.b=2;
end
可以得到返回主函数aa有两个字段
%% Initialize constants, settings =========================================
settings = initSettings();
%% Generate plot of raw data and ask if ready to start processing =========
try
fprintf('Probing data (%s)...\n', settings.fileName)
probeData(settings);
catch
% There was an error, print it and exit
errStruct = lasterror;
disp(errStruct.message);
disp(' (run setSettings or change settings in "initSettings.m" to reconfigure)')
return;
end
try catch 语句,执行try,try语句中如果不报错,则执行end。如果报错,则执行catch.
[fid, message] = fopen(settings.fileName, 'rb');% r是读取的意思,b是二进制文件
打开文件,fid就是个文件代号,后面用哪个文件就直接用代号就好了。
FID=+N(N是正整数):表示文件打开成功,文件代号是N.
FID=-1 : 表示文件打开不成功。
FID在此次文件关闭前总是有效的。
这是用了这个文件: fseek(fid, settings.skipNumberOfBytes, ‘bof’);
status=fseek(fid, offset, origin)
其中fid为文件句柄,offset表示位置指针相对移动的字节数,OFFSET values are interpreted as follows:
.>0 Move toward the end of the file.
= 0 Do not change position.
< 0 Move toward the beginning of the file.
origin表示位置指针移动的参照位置,ORIGIN values are interpreted as follows:
‘bof’ or -1 Beginning of file
‘cof’ or 0 Current position in file
‘eof’ or 1 End of file。
若定位成功,status返回值为0,否则返回值为–1。