mercredi 26 juillet 2017

Simulink - MATLAB- I have a matlab function block in Simulink with an if-statement, only one of the two actions of this if statement is executed, why?

I have the following function in a simulink block. It takes as an input the value of xi and of xihat, and assess whether xihat should be updated or not. I also want to output whether there was an update, therefore the variable update takes theenter image description here value 1 if xihat is updated and -1 if it is not. When I run the Simulink programme, I get the expected values for xihat (when plotted, the data is similar to xi but with a stairs kind of appearance). However the value of up is -1 for all of the simulation time. This is not coherent with the fact that the value of xihat is updated. I have even included a disp('yes') to show when the if statement is executed. In short, when the condition is positive definite, xihat should be updated and up should be assigned 1 and only the former is executed. How is this possible?

I have tried to run this exact same function with the same data in a matlab script and it then runs perfectly and up is coherent with xihat. I have attached an image of the subsystem in which the block is located.

I also tried to change the variable name, change the order of the statements, output the conditions etc and nothing seems to help.

Simulink subsystem with MAtlab block.:

Aucun commentaire:

Enregistrer un commentaire