Assign values to a structure using App designer
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I want to ask a simple question that bothered me a lot.
When I assign values to a struct, like below
BC.theta_res = app.theta_resEditField_3.Value;
BC.theta_sat = app.theta_satEditField_3.Value;
BC.K_sat = app.K_satEditField_3.Value;
BC.lambda = app.lambdaEditField.Value;
BC.h_s = app.h_sEditField.Value;
why they store values as characters not numbers? Each item has a single quote mark on it.
My input in the app is:
How to make it to a number?
thanks a lot!
댓글 수: 0
답변 (2개)
Dennis
2019년 4월 17일
There are two different types of edit fields in appdesigner (numeric and text). In the picture you show are only text edit fields (those are usually left aligned, while numeric fields are right aligned). The value of text edit fields is a string and should be converted to a number before doing calculations with it.
fig=uifigure;
f(1)=uieditfield(fig,'position',[100 50 80 40],'value','1');
f(2)=uieditfield(fig,'numeric','position',[100 90 80 40],'value',2);
s.theta=f(1).Value;
s.lambda=f(2).Value;
f(1).Value+5 %does not throw an error!
str2double(f(1).Value)+5
댓글 수: 4
mansour torabi
2021년 10월 1일
Simply just use str2double function:
BC.theta_res = str2double(app.theta_resEditField_3.Value);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!