Biomedical Imaging Research Lab
Signal & Image Processing Institute
Department of Electrical Engineering
University of Southern California
http://neuroimage.usc.edu/hui/
This seems a little faster for large number of dimensions:
IDX = find(A);
L = size(A);
[x{1:length(L)}] = ind2sub(L,IDX);
sub = [x{:}];
if nargout==2
v = A(IDX);
end
Something to consider.
why not simply
% the data
a=zeros(2,3,4,5,6);
a(1,1,1,1,1)=1;
a(2,2,2,2,2)=2;
a(1,2,3,4,5)=3;
% the engine (in a function)
[ind{1:ndims(a)}]=ind2sub(size(a),find(a));
ind=cat(2,ind{:});
% the result
disp(ind)
%{
1 1 1 1 1
2 2 2 2 2
1 2 3 4 5
%}
just a thought...
us
Comment only