App Designer returning Value in EditField

조회 수: 45 (최근 30일)
Giancarlo Meccariello
Giancarlo Meccariello 2021년 3월 8일
댓글: Giancarlo Meccariello 2021년 3월 8일
I wrote a code to calculate some values I insert in the Edit fields.
First of all do I have a DropDown Menu, with some values which I want to calculate with.
After I performe the calculation (with the value from DropDownMenu and values from EditField) do I want to return the result in an Edit field.
If run the programm and Insert all my values do I get the following error:
"Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 111)
'Value' must be a double scalar."
That's my code for the DropDown menu. I want to safe the value in the variable "app.d_th"
% Value changed function: aDropDown
function aDropDownValueChanged(app, event)
app.d_th = app.aDropDown.Value
end
I have a Calculation Button which looks like this. I have shortened the entire calculation. that's just to show you how it looks. The goal is when I press the Button I want to performe the calculation and display it in the "ResultEditField"
% Value changed function: BerechnenButton
function BerechnenButtonValueChanged(app, event)
value = app.BerechnenButton.Value;
d_th = app.d_th/1000 %in meter. 3.6mm = 0.0036m
p_h = app.p_h * 10^5 %Hochdruck in pascal
m_flow = d_th.^2 + p_h
app.ResultEditField.Value = m_flow
end
Any hints?

채택된 답변

Mario Malic
Mario Malic 2021년 3월 8일
편집: Mario Malic 2021년 3월 8일
Hi,
app.aDropDown.Value is one of the values in Items (if ItemsData is empty), therefore it's a character array.
if you set ItemsData as well to be numeric, then Value property will be of the same type. However, you can keep it simple and use line below to fix the issue.
app.d_th = str2num(app.aDropDown.Value)
  댓글 수: 5
Mario Malic
Mario Malic 2021년 3월 8일
Hm, you'll have to convert the output of these as variable types are different, even though their values are the same. On this one, you'll have to use the search tool and find related questions.
Giancarlo Meccariello
Giancarlo Meccariello 2021년 3월 8일
I started again with the programm and checked every step.
I found the problem, the only mistake was the missing conversion str2num!
Everything fine now!
THANK YOU

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by