How can I set the solver to 'discrete', programmatically?

6 Ansichten (letzte 30 Tage)
Harish
Harish am 11 Jan. 2024
Beantwortet: Hassaan am 11 Jan. 2024
Hi,
I want to use set_param() to set the solver-type to "Fixed-step" and solver to "discrete".
I could set the solver type by using:
myModel = 'model';
set_param(myModel, 'SolverType', 'Fixed-step')
but I receive an error with the following statement.
set_param(myModel, 'Solver', 'discrete');
The error says the following:
Invalid setting in block_diagram 'MultiplyAndAdd_harness' for parameter 'Solver'
Can anyone help me with this?

Akzeptierte Antwort

Hassaan
Hassaan am 11 Jan. 2024
To set the solver type for a specific block to "Fixed-step," you are on the right track with the following code:
myModel = 'model';
set_param(myModel, 'SolverType', 'Fixed-step');
However, for discrete blocks, you typically don't need to specify a solver type as you would for continuous blocks. Instead, you define the sample time for the block.
If you want to set a sample time for a specific block to make it discrete, you can use the set_param function as follows:
myModel = 'model';
blockName = 'YourBlockName'; % Replace with the name of your block
sampleTime = '0.1'; % Replace with your desired sample time (e.g., '0.1' for a discrete block with a 0.1-second sample time)
set_param([myModel '/' blockName], 'SampleTime', sampleTime);
Replace 'YourBlockName' with the name of the block for which you want to set the sample time. This will configure the block as a discrete block with the specified sample time.
Please make sure that 'discrete' is a valid option for the specific block in your Simulink model and that you are using the correct block name in the set_param function.
---------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Weitere Antworten (0)

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by