필터 지우기
필터 지우기

import constants to simulink

조회 수: 102 (최근 30일)
ameen
ameen 2015년 2월 25일
댓글: Charles Collins 2020년 6월 6일
I want to import some constants values from workspace to simulink.
For example i will write A=10, B=7, C=8 in an m.file then i will run it. So, it will be loaded to my work space.
How can i import them to Simulink ?? From workspace block give me an error message 'Invalid matrix-format ...'

채택된 답변

Kelly
Kelly 2015년 2월 25일
편집: Kelly 2015년 2월 26일
Hi,
Use a constant block in Simulink sources and use the variable name (A, B, C, ...) instead of a fixed value. I think with a from workspace block you need to have a Nx2 matrix variable with time in one column and corresponding value in the second column.
Edit:
If your constants are defined in the workspace then you can access them directly from Simulink. If you have A, B, and C, etc defined in the workspace you can use it in any block such as a gain block or a constant or a source block. For example:
% My init function to run before running my simulink simulation
A = 24;
B = 22;
C = .39294;
Then after running this file (you can use Callbacks to run it automatically when you start a simulation as Mischa has described) The variables are available in the workspace for Simulink to access them. Now as an example, I can have a "Constant" (look in "Sources" or "Commonly used Blocks") in my Simulation. I can double-click on it and simply type A or B or C and that block will output that value defined by the constant you enter. You can use the variable in any block that allows a parameter input like this.
Does that help?
Kelly
  댓글 수: 2
ameen
ameen 2015년 2월 26일
Thank you very much for your reply and help.
Charles Collins
Charles Collins 2020년 6월 6일
Please do explain more. I have never been able to access workspace variables from SimuLink, and I have been doing this since 1990.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Mischa Kim
Mischa Kim 2015년 2월 25일
Ameen, a standard approach is through callbacks. In your Simulink model go to > File > Model Properties > Model Properties, navigate to the Callbacks tab and add commands as necessary. See the documentation for more detail.
  댓글 수: 3
Mischa Kim
Mischa Kim 2015년 2월 25일
편집: Mischa Kim 2015년 2월 25일
You can simply assign the values for A, B, etc. in the InitFcn callback. Treat the text window just like you would work in the MATLAB command window. Alternatively, you can execute scripts, if you need to load more stuff.
Here is another doc.
ameen
ameen 2015년 2월 25일
which block will use the defined variables in the InitFcn callback ?

댓글을 달려면 로그인하십시오.


Saburi Ashtekar
Saburi Ashtekar 2018년 2월 2일
a=10 b=20

카테고리

Help CenterFile Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by