Is there a way to search an array for each value in a vector and return how many of each entry were found?

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?

 채택된 답변

This should work.
a = [5,6,3;10,1,24;1,2,3];
v =[1,3,5,7];
w=zeros(size(v));
for k=1:numel(v)
w(k)=numel(find(a==v(k)));
end

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2016년 2월 8일

답변:

2016년 2월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by