【Matlab】matlab常用函数(自定义)

Matlab强大的函数库涉及各个领域

matlab各个领域的函数库:https://ww2.mathworks.cn/matlabcentral/fileexchange/

发现向量arrayA中最小的Num个数

function [ minFlags ] = findMinFlag( arrayA,num )
%FINDMINFLAG Summary of this function goes here
%   Detailed explanation goes here
minFlags = [];
for i = 1:num
    [~,tempFlag] = min(arrayA);
    minFlags = [minFlags;tempFlag];
    arrayA(tempFlag) = inf;
end
minFlags = sort(minFlags,'ascend');
end


GNSS坐标转换成NEU方向以及时间转换代码链接

https://github.com/XiaoGongWei/Ubuntu16.04-llaptop-Code/blob/master/store_data/CoordTransfer.zip
XYZ_NEU.m代码调用方式如下XYZ_NEU。
ppp_pos是求解坐标,true_pos是真实坐标。

function plot_ppp_pos( ppp_pos, true_pos )
%PLOT_PPP_POS Summary of this function goes here
%   Detailed explanation goes here
data_len = length(ppp_pos);
diff_pos_NEU = zeros(data_len, 3);
for i = 1:data_len
    diff_pos_NEU(i,:) = XYZ_NEU(ppp_pos(i, :), ppp_pos(i, :) - true_pos);
end

h2 = figure;
hold on
plot(diff_pos_NEU,'.');
legend('dN','dE','dU')

end

Matlab读取txt文件

function [ Out_mat ] = readmyTxt( txtFilename, beginFlag, selectFlag )
%READMYTXT Summary of this function goes here
%   Detailed explanation goes here
Out_mat = [];

fid = fopen(txtFilename, 'r');
if fid == -1
    error('open file bad.');
    return ;
end

while ~feof(fid)
    strline_t = fgetl(fid);
    strline = strline_t(beginFlag:end);
    strline = strrep(strline, ':', ' ');
    vct_line = str2num(strline);
    myvct = vct_line(selectFlag);
    Out_mat = [Out_mat; myvct];   
end
fclose(fid);

end


集合剔除元素

setdiff([1:11],[2,4,5])
ans =     1     3     6     7     8     9    10    11

plot关闭显示窗口

set(0,‘DefaultFigureVisible’, ‘off’)

BLH转XYZ

clear
clc
close all

load CSRS_BLH.mat
data_len = size(CSRS_BLH, 1);
Cs=GetCoordSys('1984');
XYZ_mat = [];
for i = 1:data_len
    [X,Y,Z]=BLH_XYZ(CSRS_BLH(i, 1)*pi / 180, CSRS_BLH(i, 2)*pi / 180, CSRS_BLH(i, 3),Cs);
    XYZ_mat = [XYZ_mat; X Y Z];
end

plot3(XYZ_mat(:,1), XYZ_mat(:,2), XYZ_mat(:,3))

save CSRS_XYZ.mat XYZ_mat

多个坐标轴

 clc;clear all;
x=[1 2 3 4 5];%ºá×ø±ê
y1=[10 20 30 40 50];%×Ý×ø±ê1ζÈ
y2=[500 400 300 200 100];%×Ý×ø±ê2ѹÁŠ
hold on;
[ax,h1,h2]=plotyy(x,y1,x,y2);
set(get(ax(1),'Ylabel'),'string','Temperature, \circC');
set(get(ax(2),'Ylabel'),'string','Pressure, GPa');
xlabel('feed ,\mum');
hold off;

你可能感兴趣的:(Matlab)