why the error is coming?
显示 更早的评论
Trying to execute this code but it shows error "Subscript indices must either be real positive integers or logicals."
[M,N]=size(x); y=zeros(1,N); for l=1:N sum1=sum(x(:,l).*log(x(:,l))); sum1=-1*sum1; y(1,l)=sum1; end
采纳的回答
更多回答(1 个)
Roger Stafford
2014-6-24
编辑:Roger Stafford
2014-6-24
It is likely that somewhere in your system you have defined a variable named either 'sum', 'log', 'size', or 'zeros'. If so, this would be in conflict with one of matlab's functions with the same name and this would give rise to the error message you are receiving.
You can also write it as:
y = sum(-x.*log(x),1);
1 个评论
Alfonso Nieto-Castanon
2014-6-24
my money is on sum being a variable, given the choice of variable names used in the example...
clear sum;
should fix this issue...
类别
在 帮助中心 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!