In the matlab documentation, it says:
" [row col] = find(X)
If X is an N-dimensional array with N > 2, col contains linear indices for the columns "
Is there an easy way to extract the actual indices instead of the 'linear indices' ??
In
a=zeros(4,4,4,4); a(1,2,1,1)=1;
find(a) gives the answer: 5
Is there a way to get the answer: [1 2 1 1] ??
|
|
0
|
|
|
|
Reply
|
Juliette
|
12/29/2009 4:32:02 AM |
|
Juliette:
Not with one function call, that I know of - you need two.
You need to follow up the call to find with a call to ind2sub().
Like this:
workspace; % Display workspace panel.
a=zeros(4,4,4,4);
a(1,2,1,1)=1;
linearIndexes = find(a ~= 0)
% Get the index in each of the 4 dimensions.
[d1 d2 d3 d4] = ind2sub(size(a), linearIndexes)
Output:
linearIndexes =
5
d1 =
1
d2 =
2
d3 =
1
d4 =
1
Regards,
ImageAnalyst
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
12/29/2009 4:53:50 AM
|
|
"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <hhc0o2$rs0$1@fred.mathworks.com>...
> In the matlab documentation, it says:
>
> " [row col] = find(X)
> If X is an N-dimensional array with N > 2, col contains linear indices for the columns "
>
> Is there an easy way to extract the actual indices instead of the 'linear indices' ??
>
> In
> a=zeros(4,4,4,4); a(1,2,1,1)=1;
>
> find(a) gives the answer: 5
>
> Is there a way to get the answer: [1 2 1 1] ??
ImageAnalyst gave the solution, but I have to ask. Are you sure you need this?
Typically, in MATLAB, you can accomplish most things with linear indices just as well as with"actual" indices, and with less computational effort. You can often even accomplish them without any indices at all.
|
|
0
|
|
|
|
Reply
|
Matt
|
12/29/2009 1:35:05 PM
|
|
Thanks ImageAnalyst!
That was very helpful!
Matt J,
I simply needed to see the indices (not use them for anything).
Cheers,
|
|
0
|
|
|
|
Reply
|
juliette.physicist (183)
|
12/30/2009 3:30:08 AM
|
|
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <3554c0f2-b908-4197-9f06-7ed12e5771d7@r24g2000yqd.googlegroups.com>...
> Juliette:
> Not with one function call, that I know of - you need two.
> You need to follow up the call to find with a call to ind2sub().
> Like this:
>
> workspace; % Display workspace panel.
> a=zeros(4,4,4,4);
> a(1,2,1,1)=1;
> linearIndexes = find(a ~= 0)
> % Get the index in each of the 4 dimensions.
> [d1 d2 d3 d4] = ind2sub(size(a), linearIndexes)
just a minor change towards versatility...
a=zeros(4,4,4,4);
a(1,4,2:3,3)=1;
lix=find(a);
clear r;
[r{1:ndims(a)}]=ind2sub(size(a),lix);
r=cat(2,r{:})
%{
% r =
1 4 2 3
1 4 3 3
%}
us
|
|
0
|
|
|
|
Reply
|
us
|
12/30/2009 3:22:02 PM
|
|
|
4 Replies
400 Views
(page loaded in 0.075 seconds)
Similiar Articles: find non-zero elements in N-D array - comp.soft-sys.matlab ...In the matlab documentation, it says: " [row col] = find(X) If X is an N-dimensional array with N > 2, col contains linear indices for the columns... find index in an array - comp.soft-sys.math.mathematicafind non-zero elements in N-D array - comp.soft-sys.matlab ... repmat elements of cell array - comp.soft-sys.matlab find non-zero elements in N-D array - comp.soft-sys ... Extract all non zero rows from array - comp.soft-sys.matlab ...Find an element in a cell array - comp.soft-sys.matlab find non-zero elements in N-D array - comp.soft-sys.matlab ... Extract all non zero rows from array - comp.soft-sys ... Unable to access the elements in an array with array[1][0] - comp ...... array - comp.soft-sys.matlab ... 6 Replies 235 Views (0.066 seconds) Tweet ... all non zero rows from array - comp.soft-sys.matlab ... find non-zero elements in N-D array ... Find an element in a cell array - comp.soft-sys.matlabfind non-zero elements in N-D array - comp.soft-sys.matlab ... repmat elements of cell array - comp.soft-sys.matlab find non-zero elements in N-D array - comp.soft-sys ... extracting elements from a cell array - comp.soft-sys.matlab ...Find an element in a cell array - comp.soft-sys.matlab find non-zero elements in N-D array - comp.soft-sys.matlab ... Extract all non zero rows from array - comp.soft-sys ... using min to find non-zero minimum - comp.soft-sys.matlab ...find non-zero elements in N-D array - comp.soft-sys.matlab ... using min to find non-zero minimum - comp.soft-sys.matlab ... find non-zero elements in N-D array - comp ... to get indices of an array - comp.soft-sys.matlabfind non-zero elements in N-D array - comp.soft-sys.matlab ... In the matlab documentation, it says: " [row col] = find(X) If X is an N-dimensional array with N > 2, col ... namelist input of multidimensional array? - comp.lang.fortran ...find non-zero elements in N-D array - comp.soft-sys.matlab ... namelist input of multidimensional array? - comp.lang.fortran ..... how to input a 2-D (or, in principle, n ... Loop to evaluate consecutive values in array - comp.soft-sys ...find non-zero elements in N-D array - comp.soft-sys.matlab ... compare values in the same field in consecutive rows--and store ... Extract all non zero ... contains the ... find non-zero elements in N-D array - Newsreader - MATLAB CentralIn the matlab documentation, it says:" [row col] = find(X) If X is an N-dimensional array with N > 2, col contains linear indices for the columns " find non-zero elements in N-D array - comp.soft-sys.matlab ...In the matlab documentation, it says: " [row col] = find(X) If X is an N-dimensional array with N > 2, col contains linear indices for the columns... 7/22/2012 8:26:37 AM
|