Filter löschen
Filter löschen

Loop question (general programming)

2 Ansichten (letzte 30 Tage)
João Araújo
João Araújo am 11 Apr. 2019
Beantwortet: Bob Thompson am 11 Apr. 2019
Hi, I am trying to script a function based on find_system in matlab, and I am trying to do the following:
I am getting a parameter name from a list of parameters for a Simulink model, lets take as an example "param", and finding out where it is on the simulink model by using find_system('Name','param'). Until here it's fine.
The problem is, sometimes these parameters have other names, depending on where they are, for example if it is a gain, it would be called "g_param" or a map, "m_param".
So I would like to script a cycle that tries to find "param", if it doesnt find it, appends "m_" to "param", and if it comes empty "g_" to "param" and so on until it hits, or fails and returns 0.
I am having trouble building a cycle for that, so if anybody has an idea, thank you for your support!

Akzeptierte Antwort

Bob Thompson
Bob Thompson am 11 Apr. 2019
I would suggest creating an array of the possible conditions you want.
A = {'param'; 'm_param'; 'g_param'};
Then you can just create a loop that breaks if you don't find what you're looking for.
for i = 1:size(A,1)
B = find_system(Name,A{i});
if ~isempty(B)
break
end
end
This is a basic example setup, and probably won't be exactly what you need, but it should get you started.

Weitere Antworten (0)

Kategorien

Mehr zu Create Large-Scale Model Components finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by