|
Hello,
At the bottom is a past post that described a one-step use of ind2sub
to find indices of 3d array elements equal to a specified value. I'm
currently using it in a task which is
1. to create a collection of 1d arrays from a 3d array, one for each
distinct value of the (integer) 3d array.
2. to then reconstruct the 3d array from the 1d arrays
3. to do all of this *fast*, in the sense that I wish to avoid 'for'
loops and such and strictly only use operations on matrices
To achieve 3, I must change my current approach where I do the
following for each distinct value.
- use the shown use of ind2sub to get the 3 indices a,b,c associated
with that value
- in the 1d array associated with that value, set each array element
one at a time, with something like
for i=1:n
array1d(i)=array3d(a,b,c)
end
How can I accomplish at least 1 and 3 together (putting aside 2 if we
must)? Thanks in advance for any help!
sureshanands@gmail.com wrote:
> I have a 3d numeric array and I need to get the subscript indices
> for all array elements equal to a specified value. The matlab
> 'find' doesn't seem to work for 3d arrays.
Bård Skaflestad wrote:
>Sure it does:
>
> [ix{1:ndims(A)}] = ind2sub(size(A), find(A(:) == value));
>
>By the way, using exact equality tests for floating point
>numbers may
>or may not be what you want.
--
Yaman Aksu
yamanaksu at yahoo dot com
|