How do I find for a particular element in a multidimensional array?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a 4 dimensional array and I would like to find a number in it and also find its position in the array. I cannot use the FIND command directly on an array which has more than 2 dimensions.
Akzeptierte Antwort
MathWorks Support Team
am 27 Jun. 2009
There is no direct function to achieve this functionality. Following example will accomplish it.
t = rand(10,10,10,10);
%assign the number that needs to be found in the array to ToBeFoundOut
ToBeFoundOut = t(1,1,1,6)
index = find(t(:) == ToBeFoundOut )
%The dimensions of the array needs to be fed as an input to ind2sub function
s = [ 10,10,10,10];
[I,J,K,L] = ind2sub(s,index)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!