Simulate & Generate C-code with out opening the Simulink model

  • Follow


Dear All,

        I want to perform simulation & C-Code Generation without opening my simulink model. By using the below code I am connecting some source blocks to my filter block and then simulate & generate the C-code out of it.

if(get(handles.Stress_Test_checkbox1,'value')) == 1
clc; bdclose all;  %This line will close all the simulink models
open_system('Digi_Filter');    % This will open 'Template_Model_V2' model

df_handle = find_system(gcs, 'Name','Digital Filter'); %Gets the handles to block 'Digital Filter'
dfport = get_param(df_handle, 'PortConnectivity');    % Gets the port parameter of %'Digital Filter'

input_port_handle = dfport{1,1}(1,1).SrcBlock;  %port hanldes to input of 'Digital %Filter'

if input_port_handle == -1 % check if there is anything connected to Digital Filter input port
    % if there is no connection, the handle is -1, otherwise, there is connection   
    disp('No connection');
    add_line('Digi_Filter','Signal From Workspace/1', 'Digital Filter/1','autorouting','on');
else
    disp(['Connected to '  get_param(dfport{1,1}(1,1).SrcBlock,'Name') ]);
    
end

%***************************%
%******Generate C-Code******%
%***************************%
rtwbuild('Digi_Filter');

%****************************************%
%*******Model Simulation Settings********%
%********Delete Line in the model********%
%****************************************%

%sim('Digi_Filter','StopTime', 'length(Test_Signal)') %Model StopTime depends
    % on the length of Test_Signal
sim('Digi_Filter','ReturnWorkspaceOutputs', 'on','StopTime', 'length(Test_Signal)');
delete_line('Digi_Filter','Signal From Workspace/1', 'Digital Filter/1');  
save_system('Digi_Filter');
close_system('Digi_Filter');

else
    errordlg('You must select Filter Response "Stress Test"','Bad Input','modal')
end

      How can I do the same without opening the simulink model. Is it possible??

Any suggestions??
0
Reply sandhi.prashant (130) 8/8/2012 12:31:09 PM

Use load_system instead of open_system

Phil.
0
Reply phil986 (301) 8/8/2012 3:21:09 PM


1 Replies
30 Views

(page loaded in 0.051 seconds)


Reply: