Filter löschen
Filter löschen

MATLAB Simulink: IF statement logic

2 Ansichten (letzte 30 Tage)
Quentin De Boever
Quentin De Boever am 16 Nov. 2020
Beantwortet: Monisha Nalluru am 18 Nov. 2020
General question, if I have code looking like this:
for x=0:500
if x <= 250
y = 2*x+1;
else
y= 3*x+2;
end
end
How could I have the same logic using blocks/systems in Simulink? Whenever I try switches and If blocks, I get an error like "Input Ports (1) of __ are involved in the loop.
I can share my model if it is helpful. But if someone could show me how to put this code in terms of a Simulink system, I'm sure I could figure it out. FYI, if it isn't obvious, x is my input and y is my output.
Thank you!

Akzeptierte Antwort

Monisha Nalluru
Monisha Nalluru am 18 Nov. 2020
For above code,
We can use Constant block to generate x and then save corresponding y values using To Workspace block based on condition using Switch block
You can also use input and outport but donot keep the port in loop. Fetch all the data once and start processing the data
As an example I am attaching the model
Also if you want data to be taken in serial then use Unbuffer block after the constant block

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by