【发布时间】:2016-07-27 21:33:50
【问题描述】:
我是八度的新手。我想为每个 theta 绘制 lh 值。我正在使用以下函数计算 lh 值。
function lh = compute_lh (D, theta)
lh = 1
for i=D
if i == 1
lh = lh * theta
else
lh = lh * (1-theta)
endif
end
endfunction
D = =[1,1,1,1,1,1,0,0,0,0] 其中 theta 是用 theta = 0:0.01:1 生成的
绘图(theta,compute_lh(D,theta))
错误:compute_lh: operator *: nonconformant arguments (op1 is 1x101, op2 is 1x101) 错误:在第 29 行第 10 列从 compute_lh 调用 错误:评估参数列表元素编号 2
我不知道为什么在绘图时将 theta 转换为矩阵。
【问题讨论】:
-
像
lh=theta.^sum(D==1).*(1-theta).^(sum(D~=1))这样的东西肯定比这更容易吗?即使lh=theta.^nnz(D).*(1-theta).^nnz(~D)D只有 1 或 0。