Code covered by the BSD License  

Highlights from
simfindvars.m

simfindvars.m

by

 

19 Jan 2012 (Updated )

To detect variables defined in the model.

simfindVars.m
% This scripts is written for detecting variable used in the model and not
% present in the workspace.. if some of them assigned in
% workspace ,rest of the undefined will be captured.

% Author : Aravindan Samarasam, Lear Automotive India Pvt Ltd.

% contact: asamarasam@lear.com,  

%% Select the Model for spec Review

clc; bdclose('all');

[Model_Name dir_name] = uigetfile({'*.mdl'},'Select the  model'); 
if ~ischar(Model_Name)
    
    return;
    
end
cd(dir_name);

load_system(Model_Name(1:end-4)); % open the model

%% load_system('TestModel');
running =1;
sheet_0 =cell(1,1);j=1;
first_stimulation = 0;

while (running == 1)
    
    try % try to run the model;
            [varoutliste]=Simulink.findVars(Model_Name(1:end-4));
            running = 0;
            
            if first_stimulation == 0
                disp('********************************************************');  
            disp('All the varibles used in the model, which are all in BASE workspace.')
                disp('********************************************************');
            end
    catch catch_error
        
            first_stimulation = 1;   
            end_limit=length(catch_error.cause);

            for loop_count=1:end_limit
                fulStr=catch_error.cause{loop_count}.message;
                str_position = strfind(fulStr,'Undefined function or variable');  
                exactVarible = fulStr(str_position+31:end-1);
                exactVarible = regexprep(exactVarible,'''','');
                assignin('base',exactVarible,0);
                sheet_0{j,1} = exactVarible; 
                j=j+1;
            end

    end

end
%% List of varibles needs to be updated in workspace. 
if first_stimulation == 1
[r c]= size(sheet_0);
fprintf('The Number of missing varibles : %d  \n',r);
fprintf('\n********************************************************\n');
fprintf('The list of missing varibles : %s  \n',sheet_0{1:end,1});
fprintf('\n********************************************************');
end

Contact us