matlab中报错Improper assignment with rectangular empty matrix.M=[1 2 3;4 5 6;7 8 9];for i=1:1:size(M,2)n(i)=find(M(:,i)==1);m(i)=length(n(i));end我就是想找出每一列中1的个数,

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 11:03:43
matlab中报错Improperassignmentwithrectangularemptymatrix.M=[123;456;789];fori=1:1:size(M,2)n(i)=find(M(

matlab中报错Improper assignment with rectangular empty matrix.M=[1 2 3;4 5 6;7 8 9];for i=1:1:size(M,2)n(i)=find(M(:,i)==1);m(i)=length(n(i));end我就是想找出每一列中1的个数,
matlab中报错Improper assignment with rectangular empty matrix.
M=[1 2 3;4 5 6;7 8 9];
for i=1:1:size(M,2)
n(i)=find(M(:,i)==1);
m(i)=length(n(i));
end
我就是想找出每一列中1的个数,

matlab中报错Improper assignment with rectangular empty matrix.M=[1 2 3;4 5 6;7 8 9];for i=1:1:size(M,2)n(i)=find(M(:,i)==1);m(i)=length(n(i));end我就是想找出每一列中1的个数,

最简单的写法:

M=[1 2 3;4 5 6;7 8 9];
sum(M==1,1)

结果:[1 0 0]