Find the position of numbers in array
9 views (last 30 days)
Hello everybody, I'm trying to find the position of some values in an array. The values i'm interested in are in a 1x182 vector and I want to find they're position in a 1x1820 vector (practically I'm just looking for a percentile). Can you guess how I can find them?
PS: i did it with a for loop using the find function but i think it is a non-efficient way, there must be an easier and fast way!
Thank a lot in advance,
Ergin Sezgin on 30 Sep 2022
Edited: Ergin Sezgin on 30 Sep 2022
Following code might help with your task:
inputArray = 100*rand(1,1820); % you should use your array
selectedElems = randperm(1820,182); % random indexing for subset,
yourVector = inputArray(selectedElems); % you should use your vector instead
elemPositions = zeros(size(yourVector)); % result vector for determined positions
elemPositions(1,i) = find(inputArray==yourVector(1,i));
isequal(selectedElems, elemPositions) % Compare real and determined positions