Borrar filtros
Borrar filtros

Loop question (general programming)

2 visualizaciones (últimos 30 días)
João Araújo
João Araújo el 11 de Abr. de 2019
Respondida: Bob Thompson el 11 de Abr. de 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!

Respuesta aceptada

Bob Thompson
Bob Thompson el 11 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre Create Large-Scale Model Components en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by