Appdesigner, knob value

5 次查看(过去 30 天)
Furkan Karaman
Furkan Karaman 2023-2-20
编辑: Voss 2023-2-20
Hello,
I have an oscilloscope-App in which I want to use 2 knobs , if I switch the knob a value to a variable should be assigned. And this value should be used in a function if a button is then pressed.
That works with one knob but not with the other. I have absolutely no idea why that is.
Does anyone have a clue?
from the appdesigner code:
function EdgeKnobValueChanged(app, event)
value = app.EdgeKnob.Value;
if strcmp(value,'rising')
app.Edge=2;
end
if strcmp(value,'falling')
app.Edge=1;
end
end
% Value changed function: CouplingKnob
function CouplingKnobValueChanged(app, event)
value = app.CouplingKnob.Value;
if strcmp(value,'AC')
app.AC=1;
app.DC=0;
end
if strcmp(value,'DC')
app.DC=1;
app.AC=0;
end
end
function StartButtonPushed(app, event)
if strcmp(app.Trigger,'Simple edge')
somefunction(app.Edge); %the value for app.Edge cant be used in the function
end
end
I would be really grateful for any kind of help.

采纳的回答

Voss
Voss 2023-2-20
编辑:Voss 2023-2-20
uiknob 'Value' is a numeric (https://www.mathworks.com/help/matlab/ref/matlab.ui.control.knob-properties.html), so both strcmp calls return false, so app.Edge is not set.
value = 3; % some numeric value
strcmp(value,'rising')
ans = logical
0
strcmp(value,'falling')
ans = logical
0
Regardless of that, you should initialize app.Edge, app.AC, and app.DC in your startupFcn to be the values corresponding to their repective knobs, in case the user clicks the start button without interacting with the knobs.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by