Effacer les filtres
Effacer les filtres

Loop question (general programming)

2 vues (au cours des 30 derniers jours)
João Araújo
João Araújo le 11 Avr 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!

Réponse acceptée

Bob Thompson
Bob Thompson le 11 Avr 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.

Plus de réponses (0)

Catégories

En savoir plus sur Create Large-Scale Model Components dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by