Changing image in an algebraic loop

조회 수: 1 (최근 30일)
Domi
Domi 2020년 6월 29일
편집: Domi 2020년 6월 29일
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
Domi
Domi 2020년 6월 29일
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 2020년 6월 29일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2020년 6월 29일
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
Fangjun Jiang
Fangjun Jiang 2020년 6월 29일
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 2020년 6월 29일
편집: Domi 2020년 6월 29일
Oh yes. Sorry! That what I meant with infinite loop. The condition never changes, s.t. the if-statement runs in ervery simulation step.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by