首页 文章

在八度音阶中绘制函数将单个值转换为矩阵

提问于
浏览
0

我是八度新人 . 我想为每个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]其中θ是以θ= 0:0.01:1生成的

情节(THETA,compute_lh(d,θ-))

错误:compute_lh:operator *:不一致的参数(op1是1x101,op2是1x101)错误:从第29行的compute_lh调用第10列错误:评估参数列表元素编号2

我不知道为什么在绘图时θ被转换为矩阵 .

1 回答

  • 0

    * 运算符是矩阵乘法 .

    您的错误发生是因为在第 lh = lh * theta 行,第一次调用它时,您're 2440587 a scalar with a horizontal matrix, resulting in a horizontal matrix. The second time, you'重新尝试使用另一个水平矩阵"matrix multiply"水平矩阵,这不是数学上正确的操作,因此您会收到错误 .

    大概你需要 .* 运算符,这是"element-wise"乘法 . 改为,你会看到你想要的钟形曲线结果 .

相关问题