Difference between two cell arrays

조회 수: 54 (최근 30일)
sumair shahid
sumair shahid 2017년 5월 10일
댓글: Walter Roberson 2017년 5월 10일
I have two cell arrays one is of 12*21cell and thw other is of 1*21 cell.I when i take their difference matlab gives me then 11*1cell rather it should give me 11*21cell. Can anybody tell me why is it so and whats the solution to this?
this is my code:
>>clc
>>clear all
>>for i=1:21
>>a=strcat('\Arranged\',int2str(i));
>>ImgPath = dir(strcat('F:\FLD\FLD_based Face Recognition System_v2',a,'\*.jpg'));%path of folder containing images
>>%sorting=natsortfiles({Path.name});
>>for k=1:length(ImgPath)
> fileNames = ImgPath(k).name;
> %S=imread(strcat('F:\FLD\FLD_based Face Recognition System_v2',a,'\',int2str(k),'.jpg'));
> I{k,i}=fileNames;
>>end
>>end
>>for j=1:length(I)
>>Test{j}=I{5,j};
>>end
>>[p,q]=setdiff(I,Test);
>>%h=setdiff(I,Test,'rows');

채택된 답변

Walter Roberson
Walter Roberson 2017년 5월 10일
You are creating cell arrays of strings. setdiff() applied to cell arrays of strings tells you all of the strings that are present in the first parameter but not present in the second parameter. setdiff(A,B) for cell arrays of strings is like
result = A; %start with the first
result( ismember(A, B) ) = []; %remove everything present in the second
setdiff() is for set membership.
setdiff() has nothing to do with telling you whether one set of named files is somehow similar to a different set of named files.
  댓글 수: 2
sumair shahid
sumair shahid 2017년 5월 10일
i am getting my answer but still it is not according to my need.i need answer in multiple rows like (for 5*3cell and 1*3cell)the answer should be 4*3 but ismember gives answer in 1*12 cell.can you please tell me how to solve this?
Walter Roberson
Walter Roberson 2017년 5월 10일
No, I cannot tell you how to solve that. Your expectation of what setdiff does appears to be incorrect.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by