Simple For Loop To Find Indices
9 views (last 30 days)
I have a question about a simple for loop. I have an original latlon set of about 500x1 unique coordinates. I have a subset of that latlon set in which I would like to find the indices for. So I have created a for loop to try to find it.
indices = zeros(length(subset),1); %create matrix of zeros to fill
indices(ii) = find(original==subset(ii));
But I keep getting: Subscripted assignment dimension mismatch. What am I doing wrong? In the end I want a matrix the size of the subset to indicate which indices are correlated to my latlon subset in relation to my original latlon.
Guillaume on 20 Apr 2015
Edited: Guillaume on 20 Apr 2015
The only way you can get this error with the code you've presented is if is find returns strictly less or more than one element, that is either the element of your subset is not found, or it is found more than once (i.e. your original array is not unique).
In any case, the loop is not needed there are set functions already present in matlab to do what you want. In your case, it's simply:
[~, indices] = ismember(subset, original)