简体   繁体   English

MATLAB / Octave-网格图问题

[英]MATLAB/Octave - Problems with mesh plot

I am trying to mesh the following function in Octave: 我正在尝试在Octave中划分以下功能:

  function C = istep(x)
      A = x < 0.75
      B = x > 0.25
      C = A & B
  endfunction

  D = rand(10);
  mesh(istep(D));

using 10x10 (random) matrix as an input. 使用10x10(随机)矩阵作为输入。 The mesh function however fails and fires 但网格功能失败并触发

invalid value for array property "zdata"

Note: Meshing D itself works fine. 注意:网格划分D本身可以正常工作。 The function istep also returns 10x10 "matrix" with expected values. 函数istep还会返回带有预期值的10x10“矩阵”。 I suspect the error lies in the fact that the internal format of the output is not treated as a matrix, but rather as a data "array" or something more abstract. 我怀疑错误在于以下事实:输出的内部格式没有被视为矩阵,而是数据“数组”或更抽象。 I am not sure how to change it however. 我不确定如何更改它。

Also, multiplying the output by eye(size(D)) solves the issue and allows to plot the matrix (i suspect it casts the output to matrix automatically). 同样,将输出乘以eye(size(D))也可以解决此问题,并允许绘制矩阵(我怀疑它会自动将输出强制转换为矩阵)。 I do not find this very elegant though and would like to avoid it if possible. 我觉得这不是很优雅,如果可能的话,我想避免这样做。

Edit: spy() works fine directly on the output, without need of multiplication by eye() 编辑: spy()直接在输出上正常工作,不需要通过eye()乘法

Question: What shall I change in the code so I am able to plot the matrix istep(D)? 问题:我应该在代码中进行哪些更改,以便能够绘制矩阵istep(D)?

The output of your function returns logical values. 函数的输出返回逻辑值。 So just do the following: 因此,请执行以下操作:

  mesh(double(istep(D)));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM