Callback GUI Drop-down Menu Not Updating Values
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Mario Malic
el 18 de Oct. de 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.
.
Respuestas (0)
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!