(1)使用matlab计算行列式的值,使用det()
>> A=[
0 0 0
1
0 0 2 0
0 3 0 0
4 0 0 0];
>> det(A)
ans
=
24
>>
(2)
matlab中使用cell创建二维数组
>> name=cell(1,5);
>>
name{1,1}='aaa';name{1,2}='bbb';name{1,3}='ccc';name{1,4}='ddd';name{1,5}='ccc';
>> name
name =
'aaa'
'bbb'
'ccc'
'ddd'
'ccc'
>>
(3)使用matlab求解线性方程组的解
sym
e.g.
2x1
+ x2 - 5x3
+ x4 = 8
x1 -
3x2
- 6x4 = 9
2x2 - x3 + 2x4 = -5
x1 + 4x2 - 7x3 + 6x4 =
0
>>
A=[2,1,-5,1;1,-3,0,-6;0,2,-1,2;1,4,-7,6];
>> B=[8;9;-5;0];
>>
C=sym(A)/sym(B);
Warning: System is
inconsistent. Solution does not
exist.
>>
C=sym(A)sym(B);
>>
C
C =
3
-4
-1
1
(4)
%第一步:先找到左右两个同步照相机中的果蝇,并把果蝇坐标分别保存到leftpoints和rightpoints中
close all;
clear;
clc;
allimg=dir('left/*.bmp');
img=rgb2gray(imread(strcat('left/',allimg(1).name)));%把图片转换成灰度图片
figure,imshow(img);
avg=zeros(size(img));%创建一个三维矩阵,用于存储每个像素的平均值
for
t=1:size(allimg)
img=rgb2gray(imread(strcat('left/',allimg(t).name)));%读取left目录下的每一张图片
avg=avg+double(img)./size(allimg,1);
end
%
figure,imshow(uint8(avg));
for
t=1;size(allimg,1)
img=double(rgb2gray(imread(strcat('left/',allimg(t).name))));%读取left目录下的每一张图片
img=imsubtract(avg,img);
figure,imshow(uint8(img));
img =
uint8(img);
hello=GRAYTHRESH(img);%计算img图片的LEVEL等级
bw=im2bw(img,0.1);
figure,imshow(bw);
s=regionprops(bw, 'centroid');%help regionprops
centroids
= cat(1, s.Centroid);
figure,imshow(bw);
hold
on
plot(centroids(:,1), centroids(:,2), 'r*');
hold
off
%figure,imshow(L);
end
(5)在一张图片的特定位置做标记
>>
BW=imread('right/cam1_0030.bmp');
>> imshow(BW);
>> hold on
>>
plot(200,200,'r*');%在图片的(200,200)位置显示红色*号
>> hold off
>>
(6)matlab读文件
point=textread('data.txt');%把data.txt中的数据读入point矩阵中,point的最大列为data.txt的最大列
point=importdata('data.txt');%把data.txt中的数据输入point中n*1的矩阵中
(7)matlab 把坐标原点设定在左上角
set(gca,'ydir','reverse','xaxislocation','top');
%注意,这个要写在plot前面
(8)在一个figure中显示多张图片
allimg=dir('../pic/*.bmp');
size(allimg)
img=imread(strcat('../pic/',allimg(1).name));
img2=imread(strcat('../pic/',allimg(200).name));
figure
subplot(2,2,1)
imshow(img)
subplot(2,2,2)
imshow(img2)
(9)在图片上标出一些点并记录这些点的坐标
allimg=dir('../pic/*.bmp');
size(allimg)
img=imread(strcat('../pic/',allimg(1).name));
imshow(img)
[x,y]=ginput(2)
hold on
plot(x,y,'r.')
(10)matlab取整
fix(x)不超过x的最大整数
ceil(x)大于x的最小整数
round(x)四舍五入取整
(11)matlab三维凸包
% X=[0 0 0;1 0 0;0 1 0;0 0 1;2 5 7];
X = 1000*rand(5000,3);
FX=convhulln(X);
trisurf(FX,X(:,1),X(:,2),X(:,3)),axis equal;
(12)在matlab中选择感兴趣的区域(Region of Interest,RIO),使用roipoly
(13)对图像进行阈值化
img=imread('F:test1.bmp');
img(find(img>85))=255;