Update an App Designer listbox if a Simulink model entity is selected
조회 수: 2 (최근 30일)
이전 댓글 표시
[ Seeking help specifically for this in Matlab 2019b ]
I made an App Designer app that populates a listbox with all the currently open Simulink models. My use-case is:
If a user clicks on one of the open models (or an entity in it like a block or signal), I'd like the listbox Value to switch to the selected model. I'm guessing I'd have to create a listener function.
Below, the first image is the model window and the second is the listbox from my Appdesigner app.
So, if the user selects the signal in the first image (blue) from the BCM_LIB model, I'd like the listbox selection (2nd image) to change to BCM_LIB. Similarly, if this user selected something in the SCCM_LIB window, I'd like the listbox selection to change to SCCM_LIB.
TIA
Joe
댓글 수: 0
답변 (1개)
Sreeram
2024년 9월 27일
Hi Joe,
I could not find a callback which is triggered when the currently selected Simulink model is changed. You can get the currently selected Simulink model using the “gcs” command. Please refer to the documentation below:
I recommend using a timer to periodically check the value of “gcs” and update the list box accordingly.
Here is how this can be done:
1. Create a private property ‘UpdateTimer’ in the app.
2. In the startup function of the app, create and start a timer. The period of update may be adjusted appropriately.
function startupFcn(app)
app.UpdateTimer = timer(...
'ExecutionMode', 'fixedRate', ...
'Period', 1.0, ...
'TimerFcn', @(~,~) updateListBox(app));
start(app.UpdateTimer);
end
3. Add the timer callback function, ‘updateListBox’ as a private function.
function updateListBox(app)
try
currentModel = gcs; % Get the current Simulink model
if ~strcmp(app.ListBox.Value, currentModel)
app.ListBox.Value = currentModel; % Update the ListBox if there's a change
end
catch
% Handle the case where gcs might fail (e.g., no model open)
app.ListBox.Value = '';
end
end
4. In the app’s close request function, stop and delete the timer object created in step 1 before deletion of ‘app’ object.
function UIFigureCloseRequest(app, event)
stop(app.UpdateTimer); % Stop the timer
delete(app.UpdateTimer);
delete(app)
end
I hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!