Is there a way to search an array for each value in a vector and return how many of each entry were found?
Ältere Kommentare anzeigen
Say I had an array a = [5,6,3;10,1,24;1,2,3] and a vector v =[1,3,5,7], and I wanted to search the array for each entry in the vector such that it would return the number of times each entry was found. e.g. in this case it should return [2,2,1,0]. Is there any way to do this?
Akzeptierte Antwort
Weitere Antworten (1)
Andrei Bobrov
am 8 Feb. 2016
sum(bsxfun(@eq,a(:)',v(:)),2)
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!