How exactly should I use open_system to open a Simulink block by using a call operation with 'handles' instead of a particular Simulink file name in GUI?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello people,
I am stuck in my following code because I cannot find out any solution to make a Simulink object, defined in 'open_system', valid in a push button tagged 'networkselector' of my GUI. 'handles.baseFileName' is the chosen file, which I succeeded to open by clicking another push button in an open file window, but I don't know how to use the call operation with 'handles' in 'open_system' correctly to be able to open the Simulink block named 'NetworkSelector' in that file. Also I hope that you help me in this issue.
Thank you very much in advance!
% push button to open a Simulink file
function open_file_Callback(hObject, eventdata, handles)
startingFolder = 'C:\Users\xxx\Documents'
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the mat file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.slx')
[handles.baseFileName, folder] = uigetfile(defaultFileName, 'Select a Simulink file')
if handles.baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, handles.baseFileName)
[name] = fileparts(fullFileName)
open_system(fullfile('C:\Users\xxx\Documents', handles.baseFileName), 'tab')
guidata( hObject, handles )
% push button to open a Simulink block named NetworkSelector
function networkselector_Callback(hObject, eventdata, handles)
handles.baseFileName
open_system('handles.baseFileName/NetworkSelector')
guidata( hObject, handles )
0 Kommentare
Antworten (1)
Abhilash Padma
am 29 Jul. 2019
Hi,
I understand that you want to open a block of a model from GUI and you are using open_system function. In order to open a block of a model, the model should be loaded into memory first. I think “NetworkSelector” is the name of the block, so you should append the string “/NetworkSelector” to the variable “handles.baseFileName” . Use the following two lines of code in networkselector_Callback function which may solve your problem.
load_system(handles.baseFileName);
open_system([handles.baseFileName ‘/NetworkSelector’]);
You can refer the following links for more information:
Siehe auch
Kategorien
Mehr zu Simulink Environment Customization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!