Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

perform a block action for only one time in SIMULINK

1,246 views
Skip to first unread message

MOOON MOOON

unread,
Nov 2, 2015, 9:47:14 PM11/2/15
to
Hello,

I want to execute or perform the action of a block in SIMULINK for only the first type the

condition is satisfied.

To clarify, I have the following example:

I have a signal coming from other block, let’s say that the entries of this signal are:

4, 9, 11, 15, 3, 20

This signal will enter to the block called “Compare To Constant”

where the input is compared to, for example, to 10.

Then, if the input is less than 10, the output of the block will give me 1,

otherwise, will give me zero. This is easy and I already did it. But, I want to do this once the

condition is satisfied for the first time and, after that, keep the output zero whatever the

coming inputs are.


So, in the above example, once the block “Compare To Constant” receives 11, it will give

zero forever and doesn’t care about the remaining entries.


Is there a way to implement that ?

riccardo

unread,
Nov 3, 2015, 4:29:08 AM11/3/15
to
"MOOON MOOON" wrote in message <n19778$2ua$1...@newscl01ah.mathworks.com>...
several ways, actually.
one of the simplest, if you don't care whether the logic runs every time step or not:
just set a counter of the Switch-ON events and put the result of the comparison in AND with the condition COUNTER < 2.

MOOON MOOON

unread,
Nov 3, 2015, 9:00:14 AM11/3/15
to

>
> several ways, actually.
> one of the simplest, if you don't care whether the logic runs every time step or not:
> just set a counter of the Switch-ON events and put the result of the comparison in AND with the condition COUNTER < 2.


thanks for your reply.

Could you please explain more..I didn't understand it completely. If you tell the exact

blocks to be used, this will be great.

I tried to implement what you have suggested. I used "N-Sample Switch". I don't know

whether this is right or wrong and I couldn't get the correct model.

Actually, the inputs are different in each simulation. What I want is once I get a number

greater than 10, I want the output to be zero and forget about the remaining entries.

I mean, we may satisfy this condition after 3 samples

in one simulation, and after 100 samples for another simulation.....etc. We can say

that the inputs have random behavior.

If there is another way, it will be very appreciated to your help.


regards

riccardo

unread,
Nov 3, 2015, 10:22:14 AM11/3/15
to
"MOOON MOOON" wrote in message <n1ael4$r9g$1...@newscl01ah.mathworks.com>...
apologies, COUNTER < 2 is wrong, it should be < 1 obviously.

you have a comparison between INPUT and 10, like INPUT <= 10, which gives you TRUE until the input gets a value > 10.
Then AFTER the 1st transition TRUE -> FALSE (i.e. the 1st value > 10) the output will stay FALSE for the rest of the simulation.

I suggested to use a COUNTER, E.G. a memory block with initial value 0, whose state gets incremented when the transition TRUE -> FALSE is detected on the result of INPUT <= 10. The output of the memory block may feed another compare-to-constant (COUNTER < 1). The 2 compare-to-constant blocks finally can feed an AND block to give you the result wanted, i.e. (INPUT < 10) AND (Number of TRUE-FALSE transitions < 1)

MOOON MOOON

unread,
Nov 3, 2015, 10:59:13 PM11/3/15
to
Ok

Thanks so much. I understand it.

I will try to implement it.


Thanks and regards
0 new messages