Discussion:
assign value different position in array
LucaLuca
2018-10-05 07:53:48 UTC
Permalink
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
LucaLuca
2018-10-05 07:53:08 UTC
Permalink
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 (idx 2..idx 1..idx 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
Andreas Weber
2018-10-05 18:00:08 UTC
Permalink
Post by 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....
LucaLuca
2018-10-05 20:53:38 UTC
Permalink
it looks good..thank you



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Continue reading on narkive:
Loading...