Azzera filtri
Azzera filtri

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

6 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Hassaan
Hassaan il 11 Gen 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.

Più risposte (0)

Categorie

Scopri di più su Event Functions in Help Center e File Exchange

Tag

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by