MATLAB Answers

How to setup common file in .XML or .txt format to declare all variables globally for using it in simulink and stateflow?

2 ビュー (過去 30 日間)
Parth Dhameliya
Parth Dhameliya 2019 年 11 月 14 日
Answered: Mark McBroom 2019 年 11 月 17 日
I am currently working on controller of robot. The conroller contains combination of Simulink blocks and Stateflow. There are too many variable as well as inputs and outputs in my program. Some inputs are used multiple time in simulink as well as stateflow. As an example DESTINATION of robot is used as an input in around 8 blocks.
I want to setup a common file in which I can define all variables as well as inputs globally so that simulink and stateflow can use that to take input.
Can anyone please help me how can I do that?

  0 件のコメント

サインイン to comment.

採用された回答

Mark McBroom
Mark McBroom 2019 年 11 月 17 日
Are these "variables" fixed during the course of the simulation? If so, create parameters in a MATLAB script file and run the script file to load them into the base workspace. Use Simulink Constant blocks or Stateflow Parameters to reference those workspace parameters from your Simulink or Stateflow model.

  0 件のコメント

サインイン to comment.

More Answers (1)

Stijn Haenen
Stijn Haenen 2019 年 11 月 14 日
Creating a txt file can be done with:
a=10; b=20; c=30; d=40;
FP=fopen(sprintf('textfile.txt'),'wt');
fprintf(FP,'variable1 = %g\n',a);
fprintf(FP,'variable2 = %g\n',b);
fprintf(FP,'variable3 = %g\n',c);
fprintf(FP,'variable4 = %g\n',d);
fclose(FP);
I'm not sure if you ment this.

  1 件のコメント

Parth Dhameliya
Parth Dhameliya 2019 年 11 月 14 日
Thank you but after creating this .txt file how can I give these variablles a,b,c,d as input to simulink and stateflow.

サインイン to comment.

サインイン してこの質問に回答します。

製品


リリース

R2018a

Translated by