In Simulink, I want to display the value of x from 0 to 5 sec with a time interval of 0.05 sec, is the above code logic inside MATLAB fcn block correct ? If, no then suggest ?

11 visualizaciones (últimos 30 días)
for t = 0:0.0001:5
display (x);
for i = 1:1:99
if (t == (0.05 * i))
pause(0.00001);
else
continue;
end
end
end
Here, 0 to 5 sec is the simulation running time.

Respuestas (1)

sai charan sampara
sai charan sampara el 22 de Sept. de 2023
Hello,
I understand that you are trying to display the value of the variable x for every 0.05 seconds using a MATLAB function block in Simulink. In Simulink all blocks are executed once in every time step. The time step depends on the choice of the solver that is used or the individual time step that has been defined for the block.
In the code mentioned in the question, the t variable used in the for loop has no relation with the run time on Simulink and hence the code just gives a display of value of “x” 100 times in each time step. Hence the above code will not work.
The value of x can be displayed for every 0.05 seconds by following these below steps:
  1. Open the Model explorer and select the MATLAB function block.
  2. Change the "Update method" to discrete and set sample time to the required value (0.05 here).
  3. Double click the function block and in the code put “display” function and then save the model.
  4. Once the model is run then we can see the expected display of the variable with 0.05 seconds interval.
You can refer to the below documentation to learn more about the properties of MATLAB function block in Simulink.

Categorías

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

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by