芯正 2021-09-02 10:37 采纳率: 60%
浏览 1549
已结题

matlab 报警变量为非标量,需要转换为标量

请帮忙分析一下如何修改。

img

报警图片如下:
img

variable 'P' might be set by a nonscalar operator.
变量“p”可以由非标量运算符来设置。

explanation
It appears the code sets the variable with an operator that does not yield a scalar value where Code Analyzer expects one. This message can be incorrect if the operator is overloaded. For information on overloading operators, see “Implementing Operators for Your Class”.
代码似乎使用一个运算符设置变量,该运算符不会产生代码分析器所期望的标量值。如果操作员过载,此消息可能不正确。有关重载运算符的信息,请参阅“为类实现运算符”。

Suggested Action
If Code Analyzer evaluated the code correctly, rewrite it to set the variable to a scalar value. Otherwise, suppress the message as described in Adjust Code Analyzer Message Indicators and Messages.
如果代码分析器正确计算了代码,请重写它以将变量设置为标量值。否则,按调整代码分析器消息指示器和消息中的说明抑制消息。

  • 写回答

1条回答 默认 最新

  • joel_1993 2021-09-02 11:08
    关注

    你好,你的P是一个向量啊,所以要循环来得到span,而且span也是一个向量,所以最终的代码是

    P = (fs/N).*fin;
    span = zeros(size(P));
    for i = 1:numel(P)
    if(P(i)<300)
    span(i) = max(round(.....)); % 这个自己填
    elseif(P(i)>=300 && P(i)<440)
    span(i) = max(rround(......));%自己填,依次类推
    ........
    end
    end
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月10日
  • 已采纳回答 9月2日
  • 修改了问题 9月2日
  • 创建了问题 9月2日