matlab function in simulink

1 次查看(过去 30 天)
Mirzakhani
Mirzakhani 2021-2-27
Hi everyone
In the Simulink environment, I encountered a problem that I want to create a discrete viewer using the MATLAB function and I did this with the for-loop. The problem is that function inputs, which are discrete signals, are not arrays and will be 1 by 1. Someone can help me?
function wr = fcn(ia,ib,va,vb)
I=[1 0;0 1];
J=[0 -1;1 0];
i_a=1;
i_b=0;
psi_a=1;
psi_b=0;
wr0=0;
for i=1:length(ia)
wr=wr0+0.2*(i_a - ia(i))*psi_a;
[i_a;i_b;psi_a;psi_b] == [I+0.1 0.5*I+0.9*wr;J+1*I J*wr+0.2*I]*[i_a;i_b;psi_a;psi_b] ...
+[I*800;0*I]*[va(i);vb(i)] - [2*I-1*J;wr*I-0.2*J]*[ia(i);ib(i)];
wr0 = wr;
end
  3 个评论
Mirzakhani
Mirzakhani 2021-2-27
I have a 4*4 array.let me explain on paper.I'm implementing a Leuenberger observer in Simulink using matlab function.
Mirzakhani
Mirzakhani 2021-2-27
How can we do multiple assignments in simulink ?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2021-2-27
You are in a MATLAB Function Block, so you need to follow MATLAB syntax.
MATLAB does not have multiple assignment in the form
[list] Operator [list]
In order to do multiple assignment in MATLAB you need one of these forms:
1)
[list] = deal(expression, expression,...)
deal is really just a function that returns multiple outputs, copying each input to its corresponding output. Example
[a, b] = deal(3,5)
2) cell expansion
[list] = somecell{:}
example
t = {3,5}
[a, b] = t{:}
3) structure expansion
[list] = Some_struct.fieldname
example
t(1).x=3;
t(2).x=5;
[a, b] = t.x
When you have a list of values of fixed size, in my opinion you should just use straight forward individual assignments: the alternatives just make the code less clear and less efficient.

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by