assign value different position in array

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

assign value different position in array

LucaLuca
hello .. I reformulated the post with better examples

a =

   NaN   NaN   NaN
   NaN   NaN   NaN
   NaN   NaN   NaN

i want to assign value 0 to last end index position(v)

v is position array

v =

   2   1   3
then :

2===> position n. 2 and n.3 =0   (last 2 element =0)
1===> position n. 3=0    (last 1 element =0)
3===> position n.1 and n.2 and n3=0  (last 3 element =0)


the result :

=Nan   0   0  
=Nan  Nan  0  
=  0   0  0  

it's possible to do it avoid loop?





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


Reply | Threaded
Open this post in threaded view
|

Re: assign value different position in array

Andreas Weber-6
Am 05.10.18 um 09:53 schrieb LucaLuca:
> i want to assign value 0 to last end index position(v)
> v is position array

a = NaN (3);
v = [2 1 3];
a(columns(a):-1:1 <= v.') = 0

a =

    NaN     0     0
    NaN   NaN     0
      0     0     0

perhaps someone comes with a better solution....


Reply | Threaded
Open this post in threaded view
|

Re: assign value different position in array

LucaLuca