注册 登录
编程论坛 Matlab

[求助]求助matlab下如何计数?非常感谢各位!

fsvance 发布于 2007-01-04 22:58, 4252 次点击

求助matlab下如何计数?
小弟初学matlab~被矩阵的计数搞糊涂了。。。

比如:
矩阵e=[1,0,1];我想计算e中的1的个数~想当然写了下边~

e=[1,0,1];
u=0;
if e[n]=0
{u=u+1;}
end

不过提示错误。。。
??? Error: File: d:\MATLAB7\work\v7.m Line: 4 Column: 3
The expression to the left of the equals sign is not a valid target for an assignment.

请教解决一下~~~谢谢各位!!

2 回复
#2
fsvance2007-01-05 10:47
谢谢~~已经解决~~~
clear
e=[1,0,0,1,0,1];
u=0;
n=0;
N=length(e);
for n=1:N;
if e(n)==1
u=u+1;
end
end
正确
#3
zhangenter2007-01-06 21:12

用u=find(e==1)不行吗?

1