Comparing elements within a cell array

Hi everyone, I have two cell arrays x and y. I want compare values of x based on y. Like x{1,1} in y contains [2,4]. So it will compare 1st element of x which is [4,7,8] with 2nd and 4th element of x and get the common values. then 2nd element of x is compared with 1st and 4th element of x because 2nd element of x is [1,4] and so on.
x= {[4,7,8];[1,5,6];[1,7,8],[1,4]}
y= {[2,4];[1,4];[1,2,4],3}
Result will look like this:
result{1,1} = {0;[7,8]} %comparison of x{1,1} with x{2,1} and x{4,1}
result{2,1}= {0;1} %comparison of x{2,1} with x{1,1} and x{4,1}
result{3,1}= {[7,8];1;1} %comparison of x{3,1} with x{1,1}, x{2,1} and x{4,1}
result{4,1}={1} %comparison of x{4,1} with x{3,1}
Zero is placed where there is no common values found.
Thanks in advance.

댓글 수: 3

Stephen23
Stephen23 2018년 8월 18일
편집: Stephen23 2018년 8월 18일
@lucksBi: Zero is not a "common value" to any of those arrays, so where does the zero come from? Why not just use an empty array?
In any case, this would be quite easy to achieve using loops and intersect, so I am sure that you must have written something. Please show us what you have tried so far.
lucksBi
lucksBi 2018년 8월 18일
편집: lucksBi 2018년 8월 18일
Sorry about that.. Actually zero is replaced with empty value.
Actually i want to do it without using loops because i have a large dataset on which i will run the code
Rik
Rik 2018년 8월 18일
I doubt there is a direct method of doing this. You could try to parallelize this by using parfor or cellfun.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2018년 8월 18일

댓글:

Rik
2018년 8월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by