Callback GUI Drop-down Menu Not Updating Values

12 vues (au cours des 30 derniers jours)
Samuel Leeney
Samuel Leeney le 18 Oct 2020
Commenté : Mario Malic le 18 Oct 2020
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 commentaire
Mario Malic
Mario Malic le 18 Oct 2020
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.
.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by