MATLAB Answers

Could anyone help me to count the number of elements present in each row are different.

1 view (last 30 days)
jaah navi
jaah navi on 31 Jan 2020
Commented: jaah navi on 31 Jan 2020
I have two different cells A and B containing the data as follows:
A=10X1 cell
'four'
'four'
'two'
'four'
'four'
'two'
'two'
'one'
'four'
'four'
B=10X1 cell
'three'
'four'
'two'
'four'
'three'
'four'
'two'
'two'
'four'
'three'
I want to compare each row of A and B is same.If they are same i need to consider it by dividing it by the total number of data(10).
could anyone please help me on it.

  0 Comments

Sign in to comment.

Answers (1)

Bhaskar R
Bhaskar R on 31 Jan 2020
result = cellfun(@(x,y)strcmp(x,y), A, B)/numel(A);

  3 Comments

jaah navi
jaah navi on 31 Jan 2020
But I actually need the result in the following manner
when i compare A and B the data present in 1,5,6,8,10 are different form A and B.
so the count of different data (here it is 5) needs to be divided by the total data(10)
so answer should be 5/10.
Could you please help me on this.
jaah navi
jaah navi on 31 Jan 2020
i got the result form the following code:
result=cellfun(@isequal, A,B);
result1=sum(result==0,1) ;
result2=result1/numel(A);
Anyway thanks for your help.

Sign in to comment.

Sign in to answer this question.