- Open the Model explorer and select the MATLAB function block.
- Change the "Update method" to discrete and set sample time to the required value (0.05 here).
- Double click the function block and in the code put “display” function and then save the model.
- Once the model is run then we can see the expected display of the variable with 0.05 seconds interval.
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 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
sai charan sampara
2023-9-22
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:
You can refer to the below documentation to learn more about the properties of MATLAB function block in Simulink.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!