MatLab App Design - how to use default value for Edit Field function?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hello,
I have an Edit Field box on the Design view and I opened a callback in the Code View. There is a default value in the Edit Field box that I would like to be used automatically when a user runs the app.
I have this:
% Value changed function: LengthEditField
function LengthEditFieldValueChanged(app, event)
app.L = app.LengthEditField.Value;
if isempty(app.L)
new_value = 3; % set default value to 3
end
app.L=new_value;
end
But when I use this variable in an equation, it tells me that its "empty (0x0) double".
How do I get it to display a value of 3 for example ?
Thank you,
채택된 답변
Cris LaPierre
2021년 11월 8일
편집: Cris LaPierre
2021년 11월 8일
The code you have shared is for capturing the value in the edit field, not setting it. Also, keep in mind that callback functions only execute when they are called (typically by the user interacting with the component).
Therefore, the best way to set a default value for a component is through its properties in the Component Browser.

It is possible to set a value programmatically, but remember that the code will only be run when the callback function it has been added to is executed.
app.LengthEditField.Value = 3
댓글 수: 11
Hi Cris,
Thank you for answering this question quickly!
I did set the default value in the Component Browser. Are you saying that if I set my variable to be 3 in the properties, then it will stay 3 unless the Edit Field value is changed by the user ?
If you set the Value to 3 in the Component Browser, then when the app launches, the edit field will be prepopulated with a 3. That will be its value until the user changes it.
But when I hover my cursor on the variable it shows me that it is empty. This is why I thought that I had to add something in the callback. This does not solve my issue.
What variable is empty? Where are you hovering your cursor over it?
A few lines later I have this equation:
app.V=app.p*10^-8.*app.L.*app.I*4/(pi.*app.D.^2);
When I hover my cursor on "app.L" it shows me "empty (0x0) double". I would like it to be 3.
Please consider sharing your app. There are too many unknowns to say with any certainty what is going on. You can attach it using the paperclip icon.
Thank you for suggesting this. I also attached a data set excel document.
The line of code you mention does not exist in the app you have shared. the closest I could find is this on line 568:
app.Va=app.pW*10^-8.*app.Lp.*app.I*4/(pi.*app.Dp.^2);
That is the one. I just simplified it in my response to your previous comment. So my concern is that all the variables that are defined by the Edit Field seem to be empty. I am sorry if this problem is bigger than it seemed initially.
Cris LaPierre
2021년 11월 9일
편집: Cris LaPierre
2021년 11월 9일
Here is what is happening. You define app.Lp and app.I as so:
% Value changed function: WdiscLengthmEditField
function WdiscLengthmEditFieldValueChanged(app, event)
app.Lp= app.WdiscLengthmEditField.Value;
end
% Value changed function: CurrentAEditField
function CurrentAEditFieldValueChanged(app, event)
app.I = app.CurrentAEditField.Value;
end
That means app.Lp and app.I will not be assigned a value unless their corresponding callback function is executed. If the variable, which is defined in Properties, is never assigned a value, it will be empty.
Perhaps the solution, then, is to get rid of all the callbacks that are just for assigning values, and instead capture the corresponding component values inside the function where you need it. See attached.
function RunButtonPushed(app, event)
% Get values
app.L = app.LengthEditField.Value;
app.errL = app.lengtherror.Value;
app.D = app.DiameterEditField.Value;
app.errD = app.diametererror.Value;
app.Lp= app.WdiscLengthmEditField.Value;
app.Dp = app.WdiscDiametermEditField.Value;
app.n3 = app.OutliersDegreesofFreedomEditField.Value;
app.I = app.CurrentAEditField.Value;
app.Lnum = app.LorenzNumberWK2EditField.Value;
Oh I understand now. That makes sense. Perfect. Thank you so much for your help!
You're the best!!
Thank you!
추가 답변 (0개)
카테고리
도움말 센터 및 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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
