24 views (last 30 days)
Mirzakhani on 27 Feb 2021
Answered: Walter Roberson on 27 Feb 2021
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
Mirzakhani on 27 Feb 2021
How can we do multiple assignments in simulink ?

Walter Roberson on 27 Feb 2021
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.

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by