extract cell depend on vector?

조회 수: 1 (최근 30일)
skysky2000
skysky2000 2017년 2월 7일
댓글: skysky2000 2017년 2월 7일
Dear all, I have vector a (1x7) and cell b (1x7), how can I extract each cell depend on elements equal in a?
a= [ 1 2 3 3 4 5 6 6];
b= { [1 2 3] [ 3 6] [ 5 6 7] [ 5 60] [ 5 6 5] [ 6 7 1 0] [ 88 99] [ 7 8 99] }
result should be:
res= {[ 5 6 7] [ 5 60] [ 6 7 1 0] [ 88 99]}
Thanks...
  댓글 수: 1
Stephen23
Stephen23 2017년 2월 7일
Why is [ 7 8 99] not in the output ?

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2017년 2월 7일
The latest explanation is much clearer:
a = [ 3 2 1 3 6 5 4 6];
b = { [1 2 3] [ 3 6] [ 5 6 7] [ 5 60] [ 5 6 5] [ 6 7 1 0] [ 88 99] [ 7 8 99] };
result = b(arrayfun(@(v) sum(a == v)>1, a))
  댓글 수: 1
skysky2000
skysky2000 2017년 2월 7일
That amazing Guillaume ... thanks alot

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Stephen23
Stephen23 2017년 2월 7일
편집: Stephen23 2017년 2월 7일
>> a = [1,2,3,3,4,5,6,6];
>> b = {[1,2,3],[3,6],[5,6,7],[5,60],[5,6,5],[6,7,1,0],[88,99],[7,8,99]};
>> c = b(cellfun(@(v)~all(ismember(v,a)),b))
>> c{:}
ans =
5 6 7
ans =
5 60
ans =
6 7 1 0
ans =
88 99
ans =
7 8 99
  댓글 수: 4
Guillaume
Guillaume 2017년 2월 7일
Kudos to Stephen for figuring out what you want (maybe!) but really, you need to express yourself a lot clearer.
"There are only 4 elements equal in vector a"
4 elements equal to what?
skysky2000
skysky2000 2017년 2월 7일
편집: skysky2000 2017년 2월 7일
Thanks Guillaume. I meant when I applied Stephen soluation, didnt give me the right result. vector a has 4 element same (3,3,6,6), and what I want 4 cells relate it to these elements.
a= [ 3 2 1 3 6 5 4 6];
b= { [1 2 3] [ 3 6] [ 5 6 7] [ 5 60] [ 5 6 5] [ 6 7 1 0] [ 88 99] [ 7 8 99] }
result={[1 2 3] [ 5 60] [ 5 6 5] [ 7 8 99]}
Thanks...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by