Loop question (general programming)

1 visualizzazione (ultimi 30 giorni)
João Araújo
João Araújo il 11 Apr 2019
Risposto: Bob Thompson il 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!

Risposta accettata

Bob Thompson
Bob Thompson il 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.

Più risposte (0)

Categorie

Scopri di più su Create Large-Scale Model Components in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by