1.直接在终端输入matlab打不开
进入/usr/local/MATLAB/R2015a/bin目录,然后sudo matlab就可以打开matlab
2.GNU Octave是一个类matlab软件,可以跑matlab的代码,本身软件比matlab小很多
3.matlab下标是从一开始的
4.矩阵分解:
>> a=magic(5) a = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 >> b=[a(1:3,1:3)] b = 17 24 1 23 5 7 4 6 13 >> c=[a(1:3,4:5)] c = 8 15 14 16 20 22
和python不同,matlab中的最后一个下标是包含的。a(1:3),在matlab中是第一行到第三行,但是在python中就是第一行到第二行,不会包括第三行。a(1:3,1:3),第一个是代表分解行,第二个是代表分解列。
matlab的下标是从1开始的,不像python从0开始
5.这是kitti将3d点云数据映射到图像上的代码(当然我修改了一些我自己的东西):
function run_demoVelodyne (base_dir,calib_dir) % KITTI RAW DATA DEVELOPMENT KIT % % Demonstrates projection of the velodyne points into the image plane % % Input arguments: % base_dir .... absolute path to sequence base directory (ends with _sync) % calib_dir ... absolute path to directory that contains calibration files % clear and close everything close all; dbstop error; clc; disp('======= KITTI DevKit Demo ======='); % options (modify this to select your sequence) if nargin<1 base_dir = '/home/sensetime/kitti_raw_data/2011_09_26_sync/2011_09_26_drive_0001_sync'; end if nargin<2 calib_dir = '/home/sensetime/kitti_raw_data/2011_09_26_calib'; end cam = 2; % 0-based index frame = 0; % 0-based index % load calibration calib = loadCalibrationCamToCam(fullfile(calib_dir,'calib_cam_to_cam.txt')); Tr_velo_to_cam = loadCalibrationRigid(fullfile(calib_dir,'calib_velo_to_cam.txt')); % compute projection matrix velodyne->image plane R_cam_to_rect = eye(4); R_cam_to_rect(1:3,1:3) = calib.R_rect{1}; P_velo_to_img = calib.P_rect{cam+1}*R_cam_to_rect*Tr_velo_to_cam; % load and display image img = imread(sprintf('%s/image_%02d/data/%010d.png',base_dir,cam,frame)); fig = figure('Position',[20 100 size(img,2) size(img,1)]); axes('Position',[0 0 1 1]); imshow(img); hold on; % load velodyne points fid = fopen(sprintf('%s/velodyne_points/data/%010d.bin',base_dir,frame),'rb'); velo = fread(fid,[4 inf],'single')'; velo %显示出这个矩阵的所有内容 fid1=fopen('/home/sensetime/kitti_raw_data/0.txt','wt') fprintf(fid1,'%8.4f %8.4f %8.4f %8.4f\n',velo') fclose(fid1) %把矩阵中所有的信息打印到txt文件上 velo = velo(1:5:end,:); % remove every 5th point for display speed fclose(fid); % remove all points behind image plane (approximation idx = velo(:,1)<5; velo(idx,:) = []; % project to image plane (exclude luminance) velo_img = project(velo(:,1:3),P_velo_to_img); % plot points cols = jet; for i=1:size(velo_img,1) col_idx = round(64*5/velo(i,1)); plot(velo_img(i,1),velo_img(i,2),'o','LineWidth',4,'MarkerSize',1,'Color',cols(col_idx,:)); end
对于一个矩阵,你要看这个矩阵的内容,直接输出这个矩阵的名字,就可以看这个矩阵的信息。后面那一段是将矩阵的信息输出到txt文件。实际上在matlab中不加分号就会输出结果,加分号就不输出结果
6.matlab一个空矩阵添加新的元素:
a = [a,x] (注意,不是括号‘( )’,而是中括号‘[ ]’)
7.matlab四舍五入取整:
B = round(A)
8.matlab的if语句和for语句都记得加end
9.matlab对矩阵求倒数,即分之一
1./a就可以了,1/a是错误的。
10.for循环递减
对于matlab的for循环,两个冒号之间是每次间隔多少,对于递增的情况,如果是1,可以不写,相当于默认了,即for i=1,3 和for i=1:1:3是相等的
但对于递减的情况,中间的冒号必须给,for i=3,1是跑不通的,必须写成for i =3:-1:1
11.一维矩阵变成二维矩阵
A = 1:10;
B = reshape(A,[5,2])