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/11/17 09:39:46

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]