Changing image in an algebraic loop

2 views (last 30 days)
Domi
Domi on 29 Jun 2020
Edited: Domi on 29 Jun 2020
Hey guys,
I have a binary image which feeds a function in SIMULINK. The function changes parts of the binary image (a map) into free space (zeros) by writing it over with zeros. This runs in a algebraic loop with a delay block. So the output of the function, which is "newmap" gets back as "oldmap" into the function. I did the loop such that this changes permanently stay on the image. You can imagine an areay which of the image which was white (1) is now black (0).
small part of the code:
function newmap = fcn(map, cond, oldmap)
newmap = map;
if (cond ~= 0)
oldmap( ceil(abs(uRobot-(coneU*(1/12)))) :floor((uRobot+(coneU*(1/12)))), vRobot:floor((vRobot+sV)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(2/12)))) :floor((uRobot+(coneU*(2/12)))), floor((vRobot+sV)):floor((vRobot+sV*2)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(3/12)))) :floor((uRobot+(coneU*(3/12)))), floor((vRobot+sV*2)):floor((vRobot+sV*3)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(4/12)))) :floor((uRobot+(coneU*(4/12)))), floor((vRobot+sV*3)):floor((vRobot+sV*4)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(5/12)))) :floor((uRobot+(coneU*(5/12)))), floor((vRobot+sV*4)):floor((vRobot+sV*5)) ) = 0;
oldmap( ceil(abs(uRobot-(coneU*(6/12)))) :floor((uRobot+(coneU*(6/12)))), floor((vRobot+sV*5)):(cv1_p) ) = 0;
newmap = oldmap;
end
So, while I unterstand that this is running in a constant loop I want that if something in the original image (input: map) changes, it should also effect the image based on the algebraic loop.
to specify the problem: there is this input called map (binary image) into the function as one can see from the picture or code. The if-statement overwrites specific areas on the map right? Ok, but when the input "map" changes over time, it does not effect the output. The output updmap/newmap goes straight into an image viewer block. So it takes it when the simulation starts and than ignores it.
I hope someone understands my problem
Thank you & best regards
  3 Comments
Domi
Domi on 29 Jun 2020
There is this input called map into the function as one can see from the picture or code. The if-statement overwrites specific areas on the map right? Ok, but when the input map changes over time, it does not effect the output. So it takes it when the simulation starts and than ignores it.
Domi
Domi on 29 Jun 2020
I need a way to have this changes by the if-statement to stay on the image. But when something changes on the starting input, it should consider it.

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 29 Jun 2020
A better way in this case is to use persistent variable. doc persistent
But a loop with memory or delay block should also work. What is inside your "algebraic loop" subsystem. I think you need to debug your model first. Put an image viewer block on map to make sure input is changing first.
  5 Comments
Fangjun Jiang
Fangjun Jiang on 29 Jun 2020
You need to be more precise and accurate. "If statement" won't run in an infinity loop.
The MATLAB Function block is executed at every simulation step. If (cond ~= 0) is always satisfied, then nothing is wrong here. You need to look outside of this block to see when and how "cond" is affected by the output of "newmap". Otherwise, if the value of "cond" never changes, then the "if statement" is always executed in every simulation step. That is probably what you mean "infinity loop".
Domi
Domi on 29 Jun 2020
Edited: Domi on 29 Jun 2020
Oh yes. Sorry! That what I meant with infinite loop. The condition never changes, s.t. the if-statement runs in ervery simulation step.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!