与下拉选项关联的数值
Numerical values associated with Drop Down options
所以我正在创建一个应用程序来计算基于一系列变量的值。变量是:
- 性别
- 年龄
- 体重
- 肌酐
应用的外观如下:
为了稍微简化流程,我决定将性别选择设为下拉菜单,这给我带来了一些问题,因为我是这样设置的:
与按钮相关的数学如下所示:
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
运行 这会产生以下错误:
Error using
matlab.ui.control.internal.model.AbstractNumericComponent/set.Value
(line 104) 'Value' must be numeric, such as 10.
据我所知,我输入ItemsData
的值是数值。我是不是错过了什么或者有更好的方法吗?
如果您在有问题的文件中的相应行中放置断点(通过 运行 下面的代码),
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'} ...
);
问题如下:
新值是 的 NaN
向量。
原因在于这一行:
final = (gender*(age)*weight) / (serum) ;
其中 serum
的值为 0
- 所以这是您应该首先处理的事情。
新值是一个矢量 of NaN
。
这是一个单独的问题,因为 set.Value
函数(当您将某些内容分配到 Value
字段时被隐式调用)需要一个 标量 。发生这种情况是因为 gender
是一个 1x4 char array
- 所以它被视为 4 个独立的数字(即关于 ItemsData
是数字的假设是不正确的)。在这种情况下,最简单的解决方案是在使用前 str2double
它。或者,将数据存储在另一个位置
(例如图形的私有属性),确保它是数字。
所以我正在创建一个应用程序来计算基于一系列变量的值。变量是:
- 性别
- 年龄
- 体重
- 肌酐
应用的外观如下:
为了稍微简化流程,我决定将性别选择设为下拉菜单,这给我带来了一些问题,因为我是这样设置的:
与按钮相关的数学如下所示:
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
运行 这会产生以下错误:
Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 104) 'Value' must be numeric, such as 10.
据我所知,我输入ItemsData
的值是数值。我是不是错过了什么或者有更好的方法吗?
如果您在有问题的文件中的相应行中放置断点(通过 运行 下面的代码),
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'} ...
);
问题如下:
新值是 的
NaN
向量。
原因在于这一行:final = (gender*(age)*weight) / (serum) ;
其中
serum
的值为0
- 所以这是您应该首先处理的事情。新值是一个矢量 of
NaN
。
这是一个单独的问题,因为set.Value
函数(当您将某些内容分配到Value
字段时被隐式调用)需要一个 标量 。发生这种情况是因为gender
是一个1x4 char array
- 所以它被视为 4 个独立的数字(即关于ItemsData
是数字的假设是不正确的)。在这种情况下,最简单的解决方案是在使用前str2double
它。或者,将数据存储在另一个位置 (例如图形的私有属性),确保它是数字。