1 / 30

Introduction to Matlab

Introduction to Matlab. Section 2. 2D – Graphics. x=0:pi/100:2*pi ; y=sin(x); plot (x,y) ; hold on ; z=cos(x) ; plot (x,z) ;. x=0:pi/100:2*pi ; y=sin(x); z=cos(x) ; subplot (2,1,1) ; plot (x,y) ; grid on; title (‘Sine function’) ; subplot (2,1,2) ; plot (x,z) ; grid off;

delila
Download Presentation

Introduction to Matlab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Matlab Section 2

  2. 2D – Graphics x=0:pi/100:2*pi ; y=sin(x); plot (x,y) ; hold on ; z=cos(x) ; plot (x,z) ;

  3. x=0:pi/100:2*pi ; y=sin(x); z=cos(x) ; subplot (2,1,1) ; plot (x,y) ; grid on; title (‘Sine function’) ; subplot (2,1,2) ; plot (x,z) ; grid off; title (‘Cosine function’) ;

  4. x=-2*pi:pi/100:2*pi ; y=sin(x); z=2*cos(x) ; subplot (2,1,1) ; plot (x,y,x,z) ; title (‘plot in same y-axis scale’); subplot (2,1,2) ; plotyy(x,y,x,z); title (‘plot in different y-axis scales’);

  5. subplot(3,1,1) ; fplot('abs(exp(-j*x*(0:9))*… ones(10,1))',[0 2*pi]); subplot(3,1,2) ; fplot('[tan(x),sin(x),cos(x)]',… 2*pi*[-1 1 -1 1]) ; subplot(3,1,3) ; fplot('sin(1 ./ x)', [0.01 0.1],… 1e-3) ; Plot a function between specified limits

  6. M=[0.5 , 1 , 1.6 , 1.2 , 0.8 , 2.1] ; N=[2 3 4 5]; subplot (1,3,1) ; pie (M) ; title (‘case 1’) ; subplot (1,3,2) ; pie (M , M==max(M)); title (‘case 2’) ; subplot (1,3,3) ; pie (N,{'North','South',… 'East','West'}) ; title (‘case 3’) ;

  7. x=[1 5 8]; y=[4 9 2]; z=[3 6 7]; a=[2 3 9 7] ; b=[5 8 6 1] ; c=[2 4.7 3 9]; subplot (2,2,1) ; fill (x,y,’r’); subplot (2,2,2) ; fill (a,b,’b’) ; subplot (2,2,3) ; fill3 (x,y,z,’r’); subplot (2,2,4) ; fill3 (a,b,c,’b’) ;

  8. x=-3:0.2:3 ; y=exp (-x .*x) ; subplot(1,2,1) ; bar(x,y) ; subplot(1,2,2) ; bar3(x,y) ;

  9. x=-3:0.2:3 ; y=exp(-x .* x) ; subplot (1,2,1) ; barh (x,y) ; subplot (1,2,2) ; stairs (x,y);

  10. x=-pi:pi/100:pi ; y=sin(x) ; plot (x,y) ; title (‘Graph of the Sine function’) ; ylabel (‘ y=sin(x)’); xlabel (‘ -\pi \leq {\itx} \leq \pi’) ; text (1,-1/3,‘ text1’) ; text1

  11. axis ([Xmin Xmax Ymin Ymax Zmin Zmax]) يحدد الإحداثيات حسب الأبعاد المدخلة من قبل المستخدم axis ([-2 2 -0.6 0.6]);

  12. axis auto يحدد الإحداثيات تلقائيا من طرف MATLAB بقيم تكون مناسبة للشكل المرسوم.

  13. axis tight يحدد الإحداثيات بمدى المعلومات المرسومة

  14. axis equal يجعل الإحداثيات في جميع الاتجاهات محدودة بنفس القيم

  15. axis square يجعل الإحداثيات على شكر مربع

  16. في حالة وجود فراغ مقابل للرمز معنى ذلك أن الناتج مشابه للرمز.

  17. example x=1:9; a=rand(3); b=rand(3); c=rand(3); figure; hold on; plot (x,a(:),'bs') ; plot (x,b(:),'gd') ; plot (x,c(:),'r^') ; plot (x,a(:).*c(:),'m*') ; hold off;

  18. Reading a Graphics Image [RGB, map] = imread('ngc6543a.jpg'); Writing Image imwrite(A,map,’filename’,fmt); imwrite(RGB,map, 'myfile.jpg', 'Quality', 100); Image types BMP (Microsoft Windows Bitmap) CUR (Microsoft Windows Cursor resource) GIF (Graphics Interchange Format) HDF (Hierarchical Data Format) ICO (Windows Icon resource JPEG (Joint Photographic Experts Group) PBM (Portable Bitmap) PCX (Windows Paintbrush) PGM (Portable Graymap) PNG (Portable Network Graphics) PPM (Portable Pixmap) RAS (Sun Raster image) TIFF (Tagged Image File Format) XWD (X Window Dump) Image Processing Toolbox

  19. Querying a Graphics File info = imfinfo(filename) Name of the file File format Version number of the file format File modification date File size in bytes Image width in pixels Image height in pixels Number of bits per pixel Image type: RGB (truecolor), intensity (grayscale), or indexed

  20. Converting Image Storage Classes • im2double, • im2uint8 • im2uint16

  21. Image Types in the Toolbox • Indexed Images • size(X) = [m,n] • imshow(X,map)

  22. Intensity Images • size(X) = [m,n] • values 0:255 • I = rgb2gray(RGB) • imshow(I)

  23. Binary image • size(X) = [m,n] • values 0,1 • imshow(BW)

  24. RGB image (True color) • size(RGB) = [m,n,c] • c=3 • values 0:255 • imshow(RGB)

  25. Display multi images [X1,map1]=imread('forest.tif'); [X2,map2]=imread('trees.tif'); subplot(1,2,1), imshow(X1,map2) subplot(1,2,2), imshow(X2,map2)

  26. Display multi images with different color map [X1,map1]=imread('forest.tif'); [X2,map2]=imread('trees.tif'); subplot(1,2,1), subimage(X1,map1) subplot(1,2,2), subimage(X2,map2)

  27. Image Arithmetic Functions

  28. example I = imread('rice.tif'); J = imread('cameraman.tif'); K = imadd(I,J); imshow(K)

  29. Exercise • Read a color image and display it • Convert it to gray image and display it • Calculate its histogram and display it as bar and line figures • Read another gray image • Display the average image • Display all images in one figure

  30. Hints • True color images

More Related