【matlab编程基础】matlab的一些编程操作

前言

 

基本操作

1. matlab中如何使用类似字典的方式进行键值操作

ids = [0 1 2 3 4 5 6];
names = {'Unknown', 'Round', 'Left', 'Right', 'Uturn', 'Bicycle', 'Pedestrain'};
sgnm = containers.Map(ids,names);
sgnm(0)

2. 已知x轴的坐标范围和射线斜率,画面中显示射线的说明;

固定y轴坐标y0,根据斜率求解x轴坐标x0,在数据点(x0,y0)添加文本;

y0 = 100;
x0 = 100/kk;
text(x0, y0, sprintf('TFL CONF is %d\nDET TFL SGN is %s', conf, sgnm(sgndir)), 'Color', 'r'); hold on;

3. 如何控制网格的大小尺寸

grid on
grid minor %  切换改变次网格线的可见性。次网格线出现在刻度线之间。并非所有类型的图都支持次网格线。

如何按照自己的想法控制网格大小

set(gca, 'XTick', -50:10:50);

 表示X坐标轴的范围是[-50 50],且每个网格是10;

4. MATLAB如何通过方向角画线

xx = -lateral:lateral;
kl = tan(0.5*pi+fov/2/180*pi);
yl = kl * xx;
plot(xx, yl,  '--m'); hold on; 
根据直线的斜率和坐标轴范围画线
        for j=1:1:dtfln
            k = floor((j+1)/2);
            dtflinfo = eval(['can.TrfficLght.TrfficLght',num2str(j)]); % timeseries对象
            dtflconf = eval(['dtflinfo.Vis_TFL_Message',num2str(k), '__Vis_TrfficLght', num2str(j), '_Conf']);
            dtflsgndir = eval(['dtflinfo.Vis_TFL_Message',num2str(k), '__Vis_TrfficLght', num2str(j), '_SgnDir']);
            dtflsts = eval(['dtflinfo.Vis_TFL_Message',num2str(k), '__Vis_TrfficLght', num2str(j), '_sts']);
            dtflx = eval(['dtflinfo.Vis_TFL_Message',num2str(k), '__Vis_TrfficLght', num2str(j), '_x']);
            conf = dtflconf.Data(i);
            sgnfir = dtflsgndir.Data(i);
            sts = dtflsts.Data(i);
            x = dtflx.Data(i);
            kk = tan(0.5*pi - (x-0.5*imgw)/imgw*fov*pi/180);
            xx = -lateral:lateral;
            yy = k * xx;
            plot(xx, yy,  'b*'); hold on;            
        end
 使用两位表示数字,比如01,02,10等;
tflx = eval(['can.TrafficLightX_',sprintf('%02s', num2str(j))]);

6. 删除某行某列;

A = magic(4);
A(2,:) = [];
A(:,3) = [];

7. 

 

 

 

 

参考

1. containers.Map

2. 控制网格的大小尺寸

3. MATLAB如何通过方向角画线

4. matlab定义循环变量

5. timeseries

6. matlab的grid网格线属性设置,修改网格线密度_毅一s的博客-CSDN博客_matlab grid on网格大小

posted on 2022-12-08 18:14  鹅要长大  阅读(416)  评论(0编辑  收藏  举报

导航