how to find differences in two simulink configuration settings using m-script

Hello,
I am comparing two simulink configuration settings using visdiff command. here is my code:
Simulink.BlockDiagram.saveActiveConfigSet(bdroot, 'active_config')
visdiff('active_config', 'standard_config')
when I type visdiff, its giving comparision report.
But what I need is, If I find any difference between config then I should say different configuation is active else its fine. This should be done using m-script.

3 Comments

I would just like to clarify what you are after. Would you like a function that compares config sets (or any variables) and just returns same/not-same as a result?
For example something like:
result = areSame('active_config', 'standard_config');
where the result is true or false?
If my understanding of your requirement is correct then there is no API to do this at the moment.
Hello Jakob.
Thanks for answering. For example, I have standard configuration settings with solver type as Fixed-step in .m file and I am using Variable-step in my active config. With below command I can save active config.
Simulink.BlockDiagram.saveActiveConfigSet(bdroot, 'active_config')
Now how to compare both settings in order to get only differences ? i.e I should say solver type is different.
I do not mind if I am using function or variable. just it should return the differences in config.
Thank you for clarifying the issue. Unfortunately there is no API available that makes this possible at the moment. The only way to view differences is, as you have already identified, to run visdiff which generates a comparison report.

Sign in to comment.

 Accepted Answer

You can return a variable if you run the function 'active_config' after you have saved it as mentioned in the question.
>> cs = active_config();
If you create two such variables for two different models, then 'isequal' is directly going to tell you if they have the exact same configurations.
Finding the exact parameters for differentiation might require to write your own api. The list of properties in a config set is already available in the same active_config.m file. Maybe, you could pass each (or only the ones you're interested into) property value one-by-one and compare. (Bit of a brutal check)

7 Comments

Hello Nobel,
Thank you for answering. After searching some forums, I found something to check all settings.
fid1 = fopen('standard_config.m');
fid2 = fopen('active_config.m');
eachLineOfStandardConfig = textscan(fid1,'%s','delimiter','\n');
eachLineOfActiveConfig = textscan(fid2,'%s','delimiter','\n');
fclose(fid1);
fclose(fid2);
eachLineOfStandardConfig = eachLineOfStandardConfig{1};
eachLineOfActiveConfig = eachLineOfActiveConfig{1};
[idx1,idx2] = ismember(eachLineOfStandardConfig,eachLineOfActiveConfig);
listOfDiff = {};
for k=1 : length(idx1)
if((idx1(k)) == 0)
configDiff=textscan(eachLineOfStandardConfig{k},'%s','delimiter','\n');
configDiff = configDiff{1};
listOfDiff = [listOfDiff configDiff];
else
flag=1;
end
end
actually listOfDiff should give all differences but its giving only last one. Could you please check and let me know what is wrong?
I am getting the differences in 1xn cell format. Also, please check the comparison order (standard vs active; or active vs standard) for ismember function - which difference are you interested in.
However, I would not rely too much on the text comparison. Some whitespace or comments can still flag a diff, I would try to compare the parameter values.
I am intrested on only active configuration.
yes. you are wright. I am getting some white spaces/comments as differences. How can I compare parameter values? can you please give code snippet ?
Thank you.
cs_s = standard_config();
cs_a = active_config();
paramList = { 'SolverType'; 'SaveOutput'}; % ..etc
% You can open the config files in editor to have an idea about the entire parameter list
% cs.set_param('ParamName', 'ParamValue');
diffList = {};
for k = 1:length(paramList)
if ~isequal(get_param(cs_s, paramList{k}), get_param(cs_a, paramList{k}))
diffList = [diffList; paramList{k}];
end
end
Hello Nobel,
sorry to ask you again, how can I give more number parameters ? for example, If want to check SystemTargetFile,ProdHWDeviceType and so on..then how can I pass parameters?
You could put them in the paramList - all the parameters which you want to check for - in that cell array.
>> paramList = { 'SolverType'; 'SaveOutput', ...
'SystemTargetFile', 'ProdHWDeviceType', ... 'and_anything_else_you_want_to_check_for'};
Thank you very much..you really helped me a lot..

Sign in to comment.

More Answers (0)

Products

Asked:

N/A
on 19 May 2015

Commented:

N/A
on 22 May 2015

Community Treasure Hunt

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

Start Hunting!