MATALB应用的一些源代码,仅供学习参考

这是MATALB应用的一些源代码,仅供学习参考

Color-coding

I=imread('rice.png');
BG=imopen(I,strel('disk',15));
I2=imsubtract(I,BG); level=graythresh(I2);
BW=im2bw(I2,level);
[labeled,numObjects]=bwlabel(BW,8);
RGB_label=label2rgb(labeled); imshow(RGB_label);

regionprops

I=imread('rice.png');
BG=imopen(I,strel('disk',15));
I2=imsubtract(I,BG); level=graythresh(I2);
BW=im2bw(I2,level);
[labeled,numObjects]=bwlabel(BW,8);
graindateregionprops(labeled,'basic');
graindate(51)

Interactive
selection

I=imread('rice.png');
    BG=imopen(I,strel('disk',15));
    I2=imsubtract(I,BG); BW=im2bw(I2,graythresh(I2));
    ObjI=bwselect(BW);   imshow(ObjI);

Values of polynomials

a=[9,-5,3,7]; x=-2:0.01:5;
f=polyval(a,x);
plot(x,f,'LineWidth',2);
xlabel('x'); ylabel('f(x)');
set(gca,'FontSize',14)

Exercise2

p=[20 -7 5 10];  q=[4 12 -3];
x=-2:0.01:1; y=conv(p,q);
f=polyval(y,x)
plot(x,f,'lineWidth',2);
xlabel('x');
n=polyder(y);
g=polyval(n,x)
hold on;
plot(x,g,'lineWidth',2);
legend('f(x)','g(x)');

Sin’(x)

h=0.05; x=0:h:2*pi;
y=sin(x); m=diff(y)./diff(x);
plot(x,y,'r');
hold on;
plot(x(1:end-1),m,'b');
legend('sin(x)','sin£§(x)');

STOP sign

t=(1:2:15)'*pi/8;    x=sin(t);  y=cos(t);
fill(x,y,'r');   axis square off;
text(0,0,'STOP','Color','w','FontSize',80,...
  'FontWeight','bold','HorizontalAlignment','center');

imagesc()

[x,y]=meshgrid(-3:.2:3,-3:.2:3);
z=x.^2+x.*y+y.^2;  surf(x,y,z);  box on;
set(gca,'FontSize',16);  zlabel('z');
xlim([-4 4]);  xlabel('x');  ylim([-4 4]);   ylabel('y');
imagesc(z); axis square; xlabel('x'); ylabel('y');

mesh & surf

x=-3.5:0.2:3.5;  y=-3.5:0.2:3.5;
[X,Y]=meshgrid(x,y);
Z=X.*exp(-X.^2-Y.^2);
subplot(1,2,1);  mesh(X,Y,Z);
subplot(1,2,2);  surf(X,Y,Z);

Bell

sphere(50);  shading flat;
light('Position',[1 3 2]);
light('Position',[-3 -1 3]);
material shiny;
axis vis3d off;
set(gcf,'Color',[1 1 1]);
view(-45,20);

Professional

load cape
X=conv2(ones(9,9)/81,cumsum(cumsum(randn(100,100)),2));
surf(X,'EdgeColor','none','EdgeLighting','Phong',...
    'FaceColor','interp');
colormap(map); caxis([-10,300]);
grid off;
axis off;

Threshold

>> I=imread('rice.png'); level=graythresh(I);
bw=im2bw(I,level); subplot(1,2,1); imshow(I);
subplot(1,2,2); imshow(bw);

Plotyy()

x=0:0.01:20;
y1=200*exp(-0.05*x).*sin(x);
y2=0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2]=plotyy(x,y1,x,y2);
set(get(AX(1),'Ylabel'),'String','Left Y-axis')
set(get(AX(2),'Ylabel'),'String','Right Y-axis')
title('Labeling plotyy');
set(H1,'LineStyle','--');
set(H2,'LineStyle',':');

Histogram

y=randn(1,1000);
subplot(2,1,1);
hist(y,10);
tltle('Bins=10');
subplot(2,1,2);
hist(y,50);
title('Bins=50');

Bar charts

x=[1 2 5 4 8];    y=[x;1:5];
subplot(1,3,1);  bar(x);  title('A bargraph of vector x');
subplot(1,3,2);  bar(y);  title('A bargraph of vector y');
subplot(1,3,3);  bar3(y);  title('A 3D bargraph');

Stacked and horizontal

x=[1 2 5 4 8];    y=[x;1:5];
subplot(1,2,1);  bar(y,'stacked');  title('stacked');
subplot(1,2,2);  barh(y);  title('Horizontal');

N polygon

x=1:100;  theta=x/10;   r=log10(x);
theta=linspace(0,2*pi,n);  r=ones(1,length(theta));
polar(theta,r);

%n is variable

Exercise1

t=linspace(0,10,51);  
y=sin((pi*t.^2)/4);
hold on;
plot(t,y);
 stem(t,y);
 hold off;
发布了4 篇原创文章 · 获赞 4 · 访问量 60

猜你喜欢

转载自blog.csdn.net/Nirvana_Tai/article/details/105391688