Compare elements of cell array

조회 수: 3 (최근 30일)
Tha saliem
Tha saliem 2017년 4월 2일
댓글: Tha saliem 2017년 4월 2일
HI I have a 2D array like this:
and a cell array:
I want to search elements of cell array in 1st column of 2D array. Like 2nd row of cell array has 4 and 3, it is present in 1st column of 2D array, it should display both rows (and all other elements as zero).
Thanks in advance.
  댓글 수: 5
Stephen23
Stephen23 2017년 4월 2일
편집: Stephen23 2017년 4월 2일
@Tha saliem: I notice that you are clearly using my code from your earlier question:
Is there a reason why you do not accept my answer... even though you are using my answer?
Also it would be much easier if you actually told us what you are trying to achieve, rather than trying to solve these small tasks. Then we could help you to develop a solution for your main task, rather then waste time trying to figure out solutions (that you do not accept) to every small task:
Tha saliem
Tha saliem 2017년 4월 2일
Im really sorry I was using it through cell phone and i clicked on Accept answer at the time when i commented on that. I didn't even know that it was not accepted. Sorry for this. and thanks for your code it really helped. The main task is quite large and i am working on it from 4 to 5 weeks so it will be difficult for me to sum it up.

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

채택된 답변

the cyclist
the cyclist 2017년 4월 2일
M = [0 1
1 0
2 1
3 0
4 1
5 0
6 0];
C = {[];[4;3];[3;1;4];2;[1;3;2;4];5;5};
output = cellfun(@(x)M(sort(x),:),C,'UniformOutput',false);
  댓글 수: 2
Tha saliem
Tha saliem 2017년 4월 2일
Thank you so much. But this is comparing based on indexes, I want to compare it based on values of first column.
Tha saliem
Tha saliem 2017년 4월 2일
Problem solved. Thanks alot for your help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by