operation with array .

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

operation with array .

gigiolone123
hi guy..i need to help to code this operation

ff=fix(rand(6)*100)
ff =

   53   28    6    6   68   78
   97   74   38   37   91   32
   18   38   18    9   82   23
   90    5   25   30   44   20
   18   87   28   42   60   64
   99   19   42   83   13   18

>> r=[1 4 2 5 6 3] (Row)
r =

   1   4   2   5  6 3    

>>col=[1 2 3 4 5 6]
col=

  1   2   3   4   5   6


i want to find element in ff by: x(as rows) and col(as colums)

i want this:

       1,1 ===>53
 
       4,2 ===>5

       2,3 ====>38

       5,4 ===>42

       6,5 ===>13

      3,6 ===>23

     
 ans=53 5 38 42 13 23    




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: operation with array .

Doug Stewart-4


On Thu, Jan 24, 2019 at 7:59 AM gigiolone123 <[hidden email]> wrote:
hi guy..i need to help to code this operation

ff=fix(rand(6)*100)
ff =

   53   28    6    6   68   78
   97   74   38   37   91   32
   18   38   18    9   82   23
   90    5   25   30   44   20
   18   87   28   42   60   64
   99   19   42   83   13   18

>> r=[1 4 2 5 6 3] (Row)
r =

   1   4   2   5  6 3     

>>col=[1 2 3 4 5 6]
col=

  1   2   3   4   5   6


i want to find element in ff by: x(as rows) and col(as colums)

i want this:

       1,1 ===>53

       4,2 ===>5

       2,3 ====>38

       5,4 ===>42

       6,5 ===>13

      3,6 ===>23


 ans=53 5 38 42 13 23     




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



what did you try?
--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: operation with array .

gigiolone123
hi,


if 've f,Col and r

I want to calculate this result (53 5 38 42 13 23)  with an automatic code






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: operation with array .

Carlo de Falco-2
In reply to this post by gigiolone123


> On 24 Jan 2019, at 13:59, gigiolone123 <[hidden email]> wrote:
>
> r =
>
>   1   4   2   5  6 3    
>
>>> col=[1 2 3 4 5 6]
> col=
>
>  1   2   3   4   5   6
>
>
> i want to find element in ff by: x(as rows) and col(as colums)
>
> i want this:
>
>       1,1 ===>53
>
>       4,2 ===>5
>
>       2,3 ====>38
>
>       5,4 ===>42
>
>       6,5 ===>13
>
>      3,6 ===>23
>
>
> ans=53 5 38 42 13 23    



I guess what you want is sub2ind :

ff = [ 53   28    6    6   68   78
       97   74   38   37   91   32
       18   38   18    9   82   23
       90    5   25   30   44   20
       18   87   28   42   60   64
       99   19   42   83   13   18];

r=[1 4 2 5 6 3];
col=[1 2 3 4 5 6];

ff(sub2ind ([6, 6], r, col))

ans =

   53    5   38   42   13   23

c.





Reply | Threaded
Open this post in threaded view
|

Re: operation with array .

gigiolone123