help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need to simplified a splitting and comparison commands


From: Francesco Potortì
Subject: Re: Need to simplified a splitting and comparison commands
Date: Wed, 12 Oct 2011 10:55:49 +0200

>The following is an example command I made (in this example only 20 random
>numbers, but as actual I want to generate 100 to 200 random numbers.  If I
>use this splitting and comparing command it will have long command, which I
>split and compare it individually.  Need an assistance how to simplify this
>maybe in function or looping.  I am new in octave and still learning for
>faster process.
>Thank you
>
>Example of 20 random number which I generated
>
>9 2 0 4 2 4 8 3 9 6 7 4 2 6 8 7 4 8 4 6
>
>The following is the command I used
>
>D1=R(1:1,1:5), D2=R(1:1,6:10), D3=R(1:1,11:15), D4=R(1:1,16:20),

This can be made much easier by using a matrix (supposing you want
integer numbers in the range 0..9:

octave> D=floor(10*rand(4,5))
D =

   8   6   0   6   6
   8   6   8   9   4
   5   6   1   2   7
   0   3   7   0   7

After which you can do your computations on D's rows.  To access row 2
of D you do:

octave> D(2,:)
ans =

   8   6   8   9   4

>E1=intersect(D1,D2), E2=intersect(D3,D4),
>F1=intersect(E1,E2),
>
>ans=
>
>D1 = 9 2 0 4 2
>D2 = 4 8 3 9 6
>D3 = 7 4 2 6 8
>D4 = 7 4 8 4 6
>
>E1 = 4 9
>E2 = 4 6 7 8
>
>F1 = 4

This can be maybe simplified, but you should tell us what is the general
purpose.  Simplifying three operations on five numbers does not make
much sense: they are simple already.

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.315.3058 (op.2111)
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Fax:    +39.050.315.2040  
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it


reply via email to

[Prev in Thread] Current Thread [Next in Thread]