필터 지우기
필터 지우기

Loop question (general programming)

조회 수: 2 (최근 30일)
João Araújo
João Araújo 2019년 4월 11일
답변: Bob Thompson 2019년 4월 11일
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!

채택된 답변

Bob Thompson
Bob Thompson 2019년 4월 11일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by