17. Дүрсийг боловсруулах: хар зураг болгон
хувиргах
RGB дүрсийг хар зураг болгон
хувиргахдаа rgb2gray командыг
ашиглана.
Жишээ: A дүрсийг хар зураг болгон
хувиргах:
B = rgb2gray(A)
18. Жишээ
clear, close all
clc
aaa = imread('d:My DocumentsMy
Pictures50294.jpg');
figure, imshow(aaa)
bbb = rgb2gray(aaa)
figure, imshow(bbb)
23. If…else Оператор
if (condition)
% if block
else
% else block
end
%
%
%
%
%
%
%
Нөхцөл
==
:
~=
:
>
:
>=
:
<=
:
<
:
тэнцүү
тэнцүү биш
эрс их
их ба тэнцүү
бага ба тэнцүү
эрс бага
24. Жишээ
clear, close all
clc
aaa = rand(1,100);
bbb = 1:1:100
color = 1;
if (color == 1)
% if block
figure, plot(bbb,aaa,':r');
else
% else block
figure, plot(bbb,aaa,'b');
end
25. Жишээ
clear, close all
clc
x = 3;
if (x > 5)
disp('The number is more than 5.')
elseif (x == 5)
disp('The number is equal to 5.')
else
disp('The number is less than 5.')
end
28. Жишээ
For давталтын доторх утгыг харуулах
clear, close all
clc
for i = 1:1:15
st1 = strcat('The value of i
inside the loop is: ',int2str(i));
disp(st1)
end
30. Жишээ
clear, close all
clc
matA = [1.4,4.2,6.7,7.0; 5.5,6.7,8.9,3.0; 0.6,6.12,5.44,8.94]
[row,col] = size(matA)
for i = 1:1:row
for j = 1:1:col
currNo = matA(i,j);
st1 = strcat('The value being tested is: ',
num2str(currNo),'.');
disp(st1)
if (currNo > 3)
disp('The current value is larger than 3.')
else
disp('The current value is less or equal than 3.')
end
end
end
32. Жишээ
clear, close all
clc
counter = 1;
while(counter <= 15)
st1 = strcat('The value of i inside the
loop is: ',int2str(counter));
disp(st1)
counter = counter + 1;
end