# 如何统计矩阵中的每一列与最后一列的值相同个数，并将结果存入一个一维矩阵，Thanks♪(･ω･)ﾉ

0

```lie = 4;
for i = 1:(lie-1)
b (1 : i)= sum(input_data(:,i)==inputdata(:,lie));
end```

```1 1 1 0
1 0 1 1
0 1 1 1```
GALI17 | 初学一级 | 园豆：96

0

``````function Array = same_column_demo(array1, array2)

Array = array1 == array2;

end``````

``````A = [ 1 2 3; 4 5 6; 1 2 3;1 1 1];
sizeA = size(A);
B = zeros(1,sizeA(1,2));

for i =1 :sizeA(1,1)-1
temp = same_column_demo(A(i,:),A(sizeA(1,1),:));
B = B + temp;
end``````
``````B
2     0     0``````

BUTTERAPPLE | 老鸟四级 |园豆：3141 | 2018-04-09 10:15

```a b c d
1 1 1 0
1 1 1 0
1 0 0 1
1 0 1 1

2 0 1 ```
GALI17 | 园豆：96 (初学一级) | 2018-04-09 11:34

@咖喱free: 哦哦， 我那个是和最后一行比较的，我修改一下代码

BUTTERAPPLE | 园豆：3141 (老鸟四级) | 2018-04-09 11:51

@咖喱free:

``````A = [ 1 1 1 0; 1 1 1 0; 1 0 0 1;1 0 1 1];
sizeA = size(A);
B = zeros(sizeA(1,1),sizeA(1,2));
C = zeros(1,sizeA(1,2)-1);

for i =1 :sizeA(1,1)-1
temp = same_column_demo(A(:,i),A(:,sizeA(1,2)));
B(:,i) = B(:,i) + temp;
C(1,i) = sum(B(:,i));
end``````

C的结果为
`C =2 0 1`

BUTTERAPPLE | 园豆：3141 (老鸟四级) | 2018-04-09 12:04

@BUTTERAPPLE: 谢谢Thanks♪(･ω･)ﾉ

GALI17 | 园豆：96 (初学一级) | 2018-04-09 14:29

您需要登录以后才能回答，未注册用户请先注册