Attachment 'zatriedovanie.txt'

Download

%  Zmysel  nasledujuceho  je  priblizit  pracu  zatriedovania, ktoru  je  mozne  zverit
%  funkcii  "histc",  avsak  je  dobre  preverit,  ze  pracuje  tak,  ako  predpokladame,
%  ze  totiz  zatrieduje  do  zlava  uzavretych  (sprava otvorenych)  podintervalov.

%  Generujme  data  ako  vektor  "x"  a  nech  vektor  "ht"  predstavuje  hranice  tried.

%  Aby  generovane data boli totozne s uvedenymi, pouzite prikaz:  "rand('state',  0)

rand('state', 0),  x = rand(1, 30)

x =

  Columns 1 through 10 

  0.9501    0.2311    0.6068    0.4860    0.8913    0.7621    0.4565    0.0185    0.8214    0.4447
  
  Columns 11 through 20 

  0.6154    0.7919    0.9218    0.7382    0.1763    0.4057    0.9355    0.9169    0.4103    0.8936 

  Columns 21 through 30 

  0.0579     0.3529    0.8132    0.0099    0.1389    0.2028    0.1987    0.6038    0.2722    0.1988


%  definujme hranice tried:
   
ht = 0:0.2:1

ht =

         0    0.2000    0.4000    0.6000    0.8000    1.0000


%  pocetnosti  tried  mozeme ziskat  funkciou  "histc":

pt = histc(x,ht)

pt =

     7     4     5     6     8     0


%  preverme,  ze  sucet  pocetnosti =  rozsah  suboru
 
sum(pt)

ans =
          30

%  OK, sedi, vsetky data su zatriedene
%  overme, ze zatriedenie sa deje do intervalov  [ ht(i);  ht(i+1)  ), 
%  t.j. do zlava uzavretych a sprava otvorenych 

sum(x < 0.2)

ans =

     7

sum( x < 0.4 ) - sum( x < 0.2 )

ans =

     4

sum( x < 0.6 ) - sum( x < 0.4 )

ans =

     5

sum( x < 0.8 ) - sum( x < 0.6 )

ans =

     6

sum( x < 1 ) - sum( x < 0.8 )

ans =

     8

%  skusme to ziskat v cykle:

for  i = 1:5,  mojept(i) = sum( x < ht(i+1) ) - sum( x < ht(i) ),  end

mojept =

     7

mojept =

     7     4

mojept =

     7     4     5

mojept =

     7     4     5     6

mojept =

     7     4     5     6     8

%  keby sme pouzili potlacenie vypisu, display by neukazoval medzivysledky ...
%  ale v  jednoduchom cykle  "for"  sme dosiahli  to, co  robi  funkcia  "histc"

diary off

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.