Callback GUI Drop-down Menu Not Updating Values

6 次查看(过去 30 天)
Hi There, I am writing a basic programme that can output a number of different signals (sin, sawtooth, etc) and vary them using mutliple sliders. There is also a drop-down menu that should alter which type of signal is outputted. I cannot get the dropdown menu to update and cannot figure out why.
Any help would be much appreciated as I am currently learning online only and we receive next to no support from the people running the module.
I am using 'updateAll', so that all sliders dropdowns, etc update the graph simultaneously when used.
Thanks in advance for the help!
function popChoice_Callback(hObject, eventdata, handles)
contents = cellstr(get(hObject,'String'));
popChoice = contents(get(hObject,'Value'));
if (strcmp(popChoice,'Sine'))
popVal = 1;
elseif (strcmp(popChoice,'Square'))
popVal = 2;
elseif (strcmp(popChoice,'Sawtooth'))
popVal = 3;
elseif (strcmp(popChoice,'Triangular'))
popVal = 4;
end
assignin('base','popVal',popVal)
updateAll()
%%Some other unrelated coder (sliders, etc) is between these functions
function updateAll
f=round(getappdata(0,'f'));
S_rate=round(getappdata(0,'S_rate'));
t=round(getappdata(0,'t'));
phi=round(getappdata(0,'phi'));
popVal = getappdata(0,'popVal');
if popVal == 1
Sin_Wave(f,phi,S_rate,t)
elseif popVal == 2
Square_Wave(f,phi,S_rate,t)
elseif popVal == 3
Sawtooth_Wave(f,phi,S_rate,t)
elseif popVal == 4
Triangle_Wave(f,phi,S_rate,t)
end
  1 个评论
Mario Malic
Mario Malic 2020-10-18
Hi Samuel,
Thank you for properly asking the question.
I believe, you should alter your code, just a little bit, the idea to solve the problem is good. Within your function getappdata, probably there's findall function and RunningAppInstance property. Great thing about that and you could do is to get the app data that way and do it only once per function call, but you are not doing so. An example:
app = get(findall(0, 'Tag', 'AppUIFigure'), 'RunningAppInstance');
Now, the app consists all stuff related to app, such as handles to the axes, property values and so on.
If you would like to get value of property in a variable (which might be unecessary, depending on the complexity of the app), just type
phi = round(app.phi)
Proceeding on to plotting, you need to include an axes handle to plot to (in App Designer, don't know about GUI, but it would be desireable to do so). You have Sin_Wave function that only gets variables, so I would assume inside you're getting as well your function getappdata, that's inefficient. You can pass an axes handle or the whole app even, up to you.
Now we're back on to the problem that I have just seen, your variable popVal is changed in callback, and assigned in base workspace, and that's not the workspace of App, therefore, function updateAll can't see variable popVal. Either you pass it as an input argument, or even better, have that variable as a property of the app, so you can access it from wherever you would like to (once you get your app instance into app).
I really hope this is understandable enough for you to proceed further.
.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by