modus mode matlab


Kasus:
Diketahui deret bilangan acak sebagai berikut:
114 105 115 115 115 100 104 111 32 98 117 115 116 97 109 105 105 105 105 111 111 104

Pertanyaan:
Bagaimana membuat program dalam matlab dimana kita mengelompokan bilangan tersebut dengan berdasarkan frequensi kemunculannya:

jawab:
Hasil nya akan sebagai berikut

114  1
105 5
115 4
100 1
104 2
111 3
32 1
98 1
117 1
116 1
97 1
109 1

beriktu scrip matlab nya

karakter_ascii=[114 105 115 115 115 100 104 111 32 98 117 115 116 97 109 105 105 105 105 111 111 104]
karakter_length=length(karakter_ascii)
for j=1:karakter_length
a=1;
for i=1:karakter_length-j
if karakter_ascii(1,j)==karakter_ascii(1,i+j)
a=a+1;
karakter_ascii(2,j)=a;
karakter_ascii(1,i+j)=0;
end
end
end

for p=1:length(karakter_ascii)
if karakter_ascii(2,p)== 0
karakter_ascii(2,p)=1;
end
end

for p=1:length(karakter_ascii)
if karakter_ascii(1,p)~= 0
karakter_ascii_new(1,p)=karakter_ascii(1,p);
karakter_ascii_new(2,p)=karakter_ascii(2,p);
end
end

matbaru=0;
for p=1:length(karakter_ascii)
if karakter_ascii(1,p)~= 0
matbaru=matbaru+1;
end
end
matbaru_tem=zeros(2,matbaru);
c=1;
for p=1:length(karakter_ascii_new)
if karakter_ascii_new(1,p)~= 0
matbaru_tem(:,c)=karakter_ascii_new(:,p);
c=c+1;
end

end
transpose(matbaru_tem)

 

Advertisements

Author: ridhobustami

orang ngak jelas

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s