How to fix this "Error using matlab.ui.​​control.i​n​ternal.m​od​el.Abst​rac​tNumer​icCo​mpone​nt/se​t.Va​lue (line 111) 'Value' must be a double scalar." ??

조회 수: 4 (최근 30일)
I want using Appdesigner to set the simulink model parameters and change them when ever via GUI. As a simple prototype wrote 2 lines code in Appdesigner wich
through set_param() function pass the value to the simulink model. I used one numeric EditFiled and one Push Button.So when I give the value and press the button to
pass it to Simulink I face this error "Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 111) 'Value' must be a double scalar".
Here is my code:
properties(Access=private)
valueToSimulink;
end
%Callbacks that handle component events
methods (Access = private)
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
app.wEditField.Value= app.valueToSimulink;
set_param('Sinwave/Constant','w',app.valueToSimulink);
end
end
Ho can I fix this error? Is there any suggestion?
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2020년 5월 29일
Samira - where is app.value set? Given the error message, I think the error is originating from
app.wEditField.Value= app.value;
but I could be wrong. Since you mention that you are using a numeric edit field, then app.value would need to be numeric and not a string (if that is what it is). Please show the line of code where you set app.value.
S Safari
S Safari 2020년 5월 29일
Hi Geoff, Thanks for your replying.
I did not explicitly define app.value. As you can see I have define in properties(Access=private), the variable "value" and fo using in my button function if I dont write "app.value" I will get an error that "value" is undefined. So how I undersood for using this varaible in other functions should be written like this.
But the error does not reffer to this value, I will edit it to be more clear.

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

답변 (1개)

Steven Lord
Steven Lord 2020년 5월 29일
Where do you assign a value to the private property valueToSimulink and what value do you assign to that property?
Set a breakpoint on the line of code where you try to assign app.valueToSimulink into the Value property of app.wEditField. When you reach that breakpoint, can you show the output of these commands?
size(app.valueToSimulink)
class(app.valueToSimulink)
My suspicion is that you've stored a handle to a component of your app in app.valueToSimulink, not a number. If so you probably want to store one of the properties of that component in app.valueToSimulink, not the component itself, or you want to assign app.valueToSimulink.Value to app.wEditField.Value and use app.valueToSimulink.Value in your set_param call.

카테고리

Help CenterFile 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!

Translated by