Simulink Matlab Function block
이전 댓글 표시
I have a Matlab workspace variable called clock_frequency.
I use this variable as a parameter in many of my simulink blocks.
I want to be able to access and alter this variable within my Simulink Matlab Function block, but I cannot do it successfully. Unlike the other simulink blocks (that can see the workspace variables) the matlab function block cannot.
I do not want to create a port and pass the variable in as a signal for various reasons.
Reading through the documentation, I have to use data store memory, but this doesn't seem to work. I got a partial version of this working, and the simulink model began running really slowly.
채택된 답변
추가 답변 (2개)
Rubem Pacelli
2019년 8월 1일
편집: Rubem Pacelli
2019년 8월 1일
10 개 추천
There are another solution for your question.
- Double-click in the MATALAB function block. Will open a script function of your "MATALAB function" block
- click on edit data
- click on add -> data (or just type cntrl+D shortcut keyword)
- type the same name of the variable tha you want pass to MATLAB function block
- In Scope, choose "Parameter" option.
It's work fine in my computer. You need save your variable in the MATLAB workspace.
댓글 수: 5
Timothy Reilly
2020년 1월 31일
Thanks Rubem,
I was struggling so much trying to find a way to do this. This was exactly what I needed to do.
By the way it doesn't seem to like cell arrays, but it seems to work with matracies of type double. Thanks again for posting this.
Tim Reilly
Jianye Xu
2020년 5월 10일
Thanks, this is a really good way, it helped me solve my problem.
Marlon Trujillo
2020년 5월 27일
What about the Interpreted Functions? I cannot see the "data" option there...
mohammad nojavan
2020년 8월 20일
hi rubem i dowloaded a simulink file from internet tath contaies some of " Data store Memory block's" . if i want to change the value of this block they dont change and when i run the simulink file the value of data store memory blocks comeback the initial values. please help me
elec.engeen2011@gmail.com
Sunandan Adhikary
2021년 2월 7일
This way we n import the variable but it does not get updated! I am trtying to update arrays in a structure and everytime it enters the function it updates that particular indexec position but later when the function is called in next iteration, those values are gone from the array.
Ryan Livingston
2013년 12월 18일
You may want to add the variable as an input parameter under the ports and data manager:
It will show up in the function block as an input argument like:
function y = fcn(u)
where 'u' will be the parameter name you choose. Then it will search through the workspaces as described in the second link.
댓글 수: 3
giulio zamboni
2019년 4월 27일
Hi, and supposing I need also to modify the matrix or array I am passing to the function, how can I do?
I would like to read and write an array in the workspace from my matlab function.
Thanks
Ali Mukhtar
2019년 9월 12일
편집: Ali Mukhtar
2019년 9월 12일
hi how can access the values of variables written in simulink function block?
Marlon Trujillo
2020년 5월 27일
This is limited to some types of variables...
카테고리
도움말 센터 및 File Exchange에서 Interactive Model Editing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!