通过比较第一列的值来访问矩阵中的一行

Phi*_*hil 1 modelica openmodelica dymola

我想通过将用户定义的参数与第一列的值进行比较来访问矩阵的特定行.

伪代码例如:

parameter Real userinput;
Real matrix[4,10] = [10,1,3,5; 3,1,5,9;.....];
Integer rowidentity;

for i in 1:10 loop
 if matrix[1,i] = userinput then
   i = rowidentity;
 end if;
end for;
Run Code Online (Sandbox Code Playgroud)

从我所知道的循环或if语句不能在等式部分之外工作.

如果没有if或for循环,我怎么能做这个任务?

Adr*_*Pop 5

编写一个返回i的函数.矩阵作为输入.然后在方程式部分中使用它.

function getIndex
  input Real userinput;
  input Real matrix[4,10] = [10,1,3,5; 3,1,5,9;.....];
  output Integer rowidentity;
algorithm
for i in 1:10 loop
 if matrix[1,i] == userinput then
   rowidentity := i;
   return;
 end if;
end for;
end getIndex;
Run Code Online (Sandbox Code Playgroud)