フィルターのクリア

I use the mouse to do some operations on Simulink, can you automatically generate code for these operations? Later, you can run the code directly to complete the previous oper

30 ビュー (過去 30 日間)
Fangping
Fangping 2024 年 6 月 24 日 1:48
コメント済み: Fangping 2024 年 7 月 2 日 5:46
I use the mouse to do some operations on Simulink, can you automatically generate code for these operations? Later, you can run the code directly to complete the previous operation.
  2 件のコメント
Ashutosh Thakur
Ashutosh Thakur 2024 年 6 月 24 日 5:06
Hi Fangping,
Can you explain more regarding the operations on which you have to generate the code ? and also the significance of mouse and your complete workflow.
Fangping
Fangping 2024 年 7 月 2 日 5:46
For example, if I use the mouse to perform the following operation, I need to display the "Alias Data Types" on the line number. So I need this operation to compile into code. So I can run this code directly and complete my mouse operation.

サインインしてコメントする。

回答 (2 件)

Dheeraj
Dheeraj 2024 年 6 月 24 日 5:18
Hi FangPing,
I understand you want to automate creating Simulink models by eliminating manual mouse clicks.
You can perform most Simulink modeling tasks programmatically in the MATLAB Command Window, such as creating models, adding blocks, and setting parameters.
Here's an example that creates a simple Simulink model with a Sine Wave block feeding into a Transfer Fcn block, which then feeds into a Scope block.
% Create a new model
model = 'ProgrammaticSimulinkModel';
new_system(model);
open_system(model);
% Add blocks
add_block('simulink/Sources/Sine Wave', [model, '/Sine Wave']);
add_block('simulink/Continuous/Transfer Fcn', [model, '/Transfer Fcn']);
add_block('simulink/Sinks/Scope', [model, '/Scope']);
% Configure block parameters
set_param([model, '/Sine Wave'], 'Amplitude', '1');
set_param([model, '/Sine Wave'], 'Frequency', '1');
set_param([model, '/Transfer Fcn'], 'Numerator', '[1]');
set_param([model, '/Transfer Fcn'], 'Denominator', '[1 1]');
% Position blocks (x, y coordinates)
set_param([model, '/Sine Wave'], 'Position', [30, 50, 60, 80]);
set_param([model, '/Transfer Fcn'], 'Position', [130, 50, 160, 80]);
set_param([model, '/Scope'], 'Position', [230, 50, 260, 80]);
% Connect blocks
add_line(model, 'Sine Wave/1', 'Transfer Fcn/1');
add_line(model, 'Transfer Fcn/1', 'Scope/1');
% Save the model
save_system(model);
% Run the simulation
set_param(model, 'SimulationCommand', 'start');
This approach allows you to create and run Simulink models programmatically.
For more details, refer to MATLAB's documentation on programmatic Simulink model management.
Thank you.

Joel Van Sickel
Joel Van Sickel 2024 年 6 月 24 日 19:25
What you are referring to is often a type of macro recording that some software supports. Matlab does not have a way to record mouse clicks performed and recreate that behavior later to get the same effect. It is assumbed if you want to automate something fully, you will use a completely programatic workflow in Matlab. Most workflows in MathWorks products include an API that allows them to be implemented programatically. Unfortunately, if this type of API doesn't exist for the task that you are doing, MathWorks does not have a workaround.

カテゴリ

Help Center および File ExchangeEvent Functions についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by