2

所以我正在创建一个应用程序来计算基于一系列变量的值。变量是:

  • 性别
  • 年龄
  • 重量
  • 肌酐

这是应用程序的外观:

显示 UI 关闭

为了稍微简化过程,我决定将性别选择设为下拉菜单,这给我带来了一些问题,因为我的设置如下:

下拉属性

与按钮相关的数学如下所示:

  function CalculateButtonPushed(app, event)
            gender = app.PatientGenderDropDown.Value ;
            age = app.PatientAgeEditField.Value ;
            weight = app.LeanBodyWeightEditField.Value ;
            serum = app.SerumCreatinineEditField.Value ;
            final = (gender*(age)*weight) / (serum) ;
            app.ResultEditField.Value = final ;
        end
    end

运行它会出现以下错误:

使用 matlab.ui.control.internal.model.AbstractNumericComponent/set.Value 时出错(第 104 行)'Value' 必须是数字,例如 10。

据我所知,我输入的值ItemsData是数值。我错过了什么还是有更好的方法来做到这一点?

4

1 回答 1

1

如果您在有问题的文件中的相应行放置断点(通过运行以下代码),

dbstop in uicomponents\+matlab\+ui\+control\+internal\+model\AbstractNumericComponent.m at 87

单击按钮后,您可以在工作区中看到以下内容:

工作区快照

这里有两个单独的问题,这两个问题都可以通过查看newValue验证码(出现在 中AbstractNumericComponent.m)来识别:

% newValue should be a numeric value.
% NaN, Inf, empty are not accepted
validateattributes(...
    newValue, ...
    {'numeric'}, ...
    {'scalar', 'real', 'nonempty'} ...
    );

以下是问题:

  1. 新值是 的向量NaN
    原因在于这一行:

    final = (gender*(age)*weight) / (serum) ;
    

    whereserum的值为0- 所以这是你应该注意的第一件事。

  2. 新值是的向量。 这是一个单独的问题,因为该函数(当您将某些内容分配给该字段时会隐式调用该函数)需要一个scalar。发生这种情况是因为是- 所以它被视为 4 个单独的数字(即关于是数字的假设是不正确的)。在这种情况下,最简单的解决方案是 在使用前对其进行处理。或者,将数据存储在另一个位置(例如图形的私有属性),确保它是数字的。NaN
    set.ValueValuegender1x4 char arrayItemsDatastr2double

于 2017-07-16T08:07:51.210 回答