lie = 4; for i = 1:(lie-1) b (1 : i)= sum(input_data(:,i)==inputdata(:,lie)); end
第三行运行出错了,不太懂要怎么写,input_data文件如下:
1 1 1 0 1 0 1 1 0 1 1 1
函数定义:same_column_demo:
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
前辈您好,首先谢谢您,这个是每一列与该列最后一个元素比较,但我想实现的是每一列与最后一列比较统计相同元素个数的值,可能我描述的不够清楚,即a、b、c列分别与d列比较
a b c d 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 1 结果: 2 0 1
@咖喱free: 哦哦, 我那个是和最后一行比较的,我修改一下代码
@咖喱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: 谢谢Thanks♪(・ω・)ノ