help-octave
[Top][All Lists]
Advanced

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

Re: multi-dimensional logical index assignment?


From: José Abílio Matos
Subject: Re: multi-dimensional logical index assignment?
Date: Sat, 02 May 2020 21:08:52 +0100

On Saturday, 2 May 2020 20.43.15 WEST Markus Mützel wrote:
> I think the problem here is that it is not possible to combine logical
> indexing with subscript indexing. Maybe converting both to linear indices
> could do the trick:
> 
> a = rand (2, 3, 4);
> sz_a = size (a);
> 
> src_pg = 4;
> target_pg = 2;
> a(find (a(:,:,src_pg)<0.5) + (target_pg-1)*prod (sz_a(1:2))) = 0;
> 
> 
> "find" effectively converts the logical indices to linear indices. The rest
> is an offset to index into the second page.
> 
> HTH,
> Markus

If it were in the fourth page the following would work:

idx3 = reshape(1+floor((0:numel(A)-1)/size(A,1)/size(A,2)), size(A));
A(A > 0.5 & idx3==4) = 0;

Such as it is I think that Markus' solution is the best we can do. :-)
-- 
José Matos






reply via email to

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