Updating GUI Popup Menu in Seperate Callback Function

조회 수: 3 (최근 30일)
Samuel Leeney
Samuel Leeney 2020년 10월 16일
답변: Ayush Bansal 2020년 10월 29일
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. I cannot get the dropdown menu to update.
I am using 'updateAll', so that all sliders dropdowns, etc update the graph simultaneously when used.
Thanks
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

채택된 답변

Ayush Bansal
Ayush Bansal 2020년 10월 29일
getappdata is used to retrieve data stored using the setappdata function.
setappdata stored data in a UI. Both these functions provide a convenient way to share data between callbacks or between separate UIs.
setappdata(0,...) sets the variable value in root not workspace.
getappdata(0,...) gets the variable value from root not workspace.
Use evalin to access data from different workspace.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by