clear;clc;%初始化 fig=imread('Q.bmp'); imshow(fig) J = imresize(fig,[240 320]); %B = imresize(A,m) returns an image B that is m times the size of A, %using nearest-neighbor interpolation. A can be an indexed image, grayscale image, %RGB, or binary image. If m is between 0 and 1.0, B is smaller than A. If m is greater than 1.0, B is larger than A. %將影像x縮放到row列,cow行的大小在這即是列240行320 r=J(:,:,1); g=J(:,:,2); b=J(:,:,3); %把rgb圖像分成課本20-11的解說 figure imshow(J) s = serial('COM1','BaudRate', 115200, 'DataBits',8, 'StopBits',1, 'FlowControl', 'none', 'Parity', 'none'); %設定參數constructs a serial port object associated with %port, PORT. If PORT does not exist or is in use you will not be able %to connect the serial port object to the device. fopen(s);% To connect the serial port object to the serial port: % 打開串列互通道 for i=1:240 for j=1:320 fwrite(s, r(i,j)); fwrite(s, g(i,j));%把資料丟到串列互通道上完成 fwrite(s, b(i,j)); end end fclose(s);% To disconnect the serial port object from the serial port. % 關閉串列互通道 delete(s) % 刪除COM1 clear s