Calculating Norm(inf) within Stateflow

5 visualizaciones (últimos 30 días)
Frederik
Frederik el 18 de Abr. de 2011
Hey,
I'm not sure if this is a bug, a feature or if I'm doing something wrong. I need to calculate a vector-norm (infinity) from time to time in stateflow.
I have two input-signals x1 and x2, both two rows, one column. When I pass these signals to an embedded matlab-function:
out1=calcnorm(x1, x2)
function y=calnorm(cx1, cx2)
y=norm(cx1+cx2, inf)
I'll get just the addition as a result, (again 2x1-Vector). This is still true if I'm using an embedded Simulink-Function containing an embedded Matlab-Funktion.
I found no limitations concerning norm and stateflow..
Any suggestions?
thanks frederik
edit: I'm working with Matlab R2010b

Respuesta aceptada

Arnaud Miege
Arnaud Miege el 19 de Abr. de 2011
Thanks for the additional comments. Yes, I was using only Simulink and can reproduce the problem in Stateflow. I worked around it by specifying explicitly the dimensions of the various inputs and outputs in the Model Explorer:
  • At the chart level, set the dimension of b & c to 2 and the dimension of out1 to 1;
  • At the Embedded MATLAB function level, set the dimensions of b1 and b2 to 2 and the dimension of y to 1.
It should work after that.
HTH,
Arnaud

Más respuestas (2)

Arnaud Miege
Arnaud Miege el 19 de Abr. de 2011
I have tried it with a MATLAB Function block (new name for Embedded MATLAB block in R2011a) and it works fine. I don't think you need the first line of the code though. Here's the code I used:
function y=calnorm(cx1, cx2)
%#codegen
y = norm(cx1+cx2, inf);
end
The %#codegen pragma is specific to R2011a, it replaces the %#eml in previous releases. I get a scalar output with the inf norm of the sum of the two input vectors.
HTH,
Arnaud

Frederik
Frederik el 19 de Abr. de 2011
thanks for your answer, unfortunately this doesn't solve my problem.
Have you tried this in Simulink or in Stateflow? In Simulink this works fine.
Even with the %#eml Statement it doesn't work. Unfortunately I'm not able to attach a minimum Realization.
Thats what I've done:
Two Constant Blocks in Simulink Containing [1;2] both entering the Chart-Block (b / c) Two states a1 and a2. One transition from a1 to a2, default transition entering a1.
The only action in a1:
entry: out1 = cal(b,c)
eM-Function:
function y=cal(b1, b2)
%#eml
y=norm(b1+b2, inf)
end
there is no difference with or without the %#eml statement
no more actions. out1 is my output to my Simulink-Scope. If I limit out1 to size=1 I'll get the following Error:
Cannot reshape Input Data 'b' (#27) ([2]) to Output Data 'out1' (#43) (scalar) for operator =. Please refer to object (#19)
#19 is my state a1
even if I declare an extrinsic matlab-function and try to calculate the norm there it won't work.
thanks for your support
frederik

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by