help-octave
[Top][All Lists]
Advanced

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

multi-dimensional logical index assignment?


From: Nicholas Jankowski
Subject: multi-dimensional logical index assignment?
Date: Sat, 2 May 2020 13:36:44 -0400

I'm trying to do a 3+ dimensional version of what is shown here:
https://stackoverflow.com/questions/18129298/how-to-use-double-indexing-to-redefine-matrix-values 

and the syntax eludes me. The example shown is clear enough for a 2D matrix, e.g.,:

>> A = [1 2; 3 4];
>> A(2,:)((A(2,:)>3)) = 0
error: () must be followed by . or close the index chain
>> A(2,A(2,:)>3) = 0
A =
   1   2
   3   0

but if I have a 3D array and I want to change the values of 'page' 2 based on the values of 'page' 4, can that be done in a similar one line assignment without using an intermediate variable?  e.g., 

>> a = rand(2,3,4);
>> a(:,:,4)>0.5
ans =
  1  1  1
  1  1  0
>> a(:,:,2)(a(:,:,4)>0.5) = 0
error: () must be followed by . or close the index chain
>> a((a(:,:,4)<0.5),2) = 0
error: Invalid resizing operation or ambiguous assignment to an out-of-bounds array element

I feel like I'm missing something obvious. 




reply via email to

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