![amplitud.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247812/amplitud.png)
How to convert Block parameter to input port?
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have a specific question about Simulink. Is it possible to convert a mask parameter to an input port?
For example, take sine block in Simulink (See the picture).
There is a parameter/field in the block parameters called Amplitude. Is it possible to make this as an input port of that block instead of specifying as a parameter?
![Screenshot from 2019-11-09 14-46-57.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247568/Screenshot%20from%202019-11-09%2014-46-57.png)
0 个评论
回答(2 个)
Jesús Zambrano
2019-11-11
Hi Rahul,
One possible simple solution would be to keep the Sine wave amplitud equal to 1, and then add the following to the block:
![amplitud.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247812/amplitud.png)
and then you create your [t,u] vector with the changes you want for the sine wave amplitud.
Hope this can help to solve your question.
Best,
Jesús
Jesús Zambrano
2019-11-16
Hi Rahul,
In general you could try to work with a MATLAB funcion block in the following way:
![mymodel.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/248634/image.png)
where the MATLAB function has the following code:
function fcn(u)
coder.extrinsic('assignin')
coder.extrinsic('set_param')
assignin('base','MyGain',u)
set_param(bdroot,'SimulationCommand','update')
In summary,an input signal goes to a MATLAB function block, which saves the value in the base workspace with name MyGain, and that parameter is then used in the Gain block.
Hope this workflow can help you.
Best,
Jesús
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!