0


I want specify some parameters of a s-functions using a variable and not using a constant inserted manually.
I have tried to define global variables in matlab and using them as paramaters and it works fine.
Anyway, i want that a variable computed in simulink is used as parameter of an other s-fuction. Is it possible? If so, how can i do it?
One idea was to continue to use global constants in matlab e to update them from simulink but i'm not able to do it because the "to workspace" block transforms them in struct or array and i need a single value.

Edit: To update the variable in the global variable in the workspace is not useful because it seems that simulink read the values at the beginning

Antonio
  • 29
  • 5

2 Answers2

0

The only solution I can think of would be to have the "variable" as one of the input signals to the S-function block, with the signal coming from some other part of the Simulink model where it's computed.

am304
  • 13,758
  • 2
  • 22
  • 40
  • I know but unfortunatly i can't change the s-function – Antonio Nov 19 '14 at 15:22
  • I think you're going to have to, to do what you want. – am304 Nov 19 '14 at 15:41
  • You are right but, the s-fuctions is closed. I can't access to the code. Anyway, a parameter can be a costant, a variable from the workspace and the result of a matlab expression.. i have try to call a matlab function and it seems to work too. Anyway you are right, it has no sense to have a simulik variable as parameter. It should be an input – Antonio Nov 19 '14 at 16:12
0

I have found a solution. First of all, it's important to know that:

  1. a s-function paramenter can be: a constant, a workspace variable, a matlab expression. In matlab expression are included calls to matlab functions.
  2. simulink computes the value of each parameter at the onset of the simulation (it has sense!).

The solution is: use a matlab function for computing the parameter. a matlab function can call an other simulink simulation. I tried it, even if in a very simple case, and it worked.

I know, it's a crazy solution but it is a solution. Warning: at the moment i'm not able to know if this crazy solution has some side effects on the simulation.

The best solution to this problem is to convert the paramenter in input of the s-function but i can't do it because it's a 3rd party sfunction

Antonio
  • 29
  • 5