Asked by Enez Furkan Cihan
on 23 Jul 2019

Function ...

...

if s<200

logic=1;

else

logic=0;

end

end

end

here I'll explain what I tryna make, assume 's' is a variable result of that firstly starting from 0 and having cumulative summation step by step. Till it arrives at 200, logic equals to 1, so far so good, where it arrives at 200, I want the logic be constant 0 always after at 200, the problem is 's' is decreasing after it got hit by 200. So that it starts to be '1' again. That's the thing I don't want it to be. If it happened in a loop, I'd use 'break', but loops is not used.

For any help, I thank you for your time in advance.

Answer by Stephen Cobeldick
on 23 Jul 2019

Edited by Stephen Cobeldick
on 24 Jul 2019

Accepted Answer

Use a nested function:

logic = true;

...

function ...

...

logic = logic && s<200;

...

end

...

Or a persistent variable:

Image Analyst
on 23 Jul 2019

Yes, how can it go back to the beginning of the function when you said " but loops is not used."???

Can you post a fully working simplified version of your program?

Enez Furkan Cihan
on 23 Jul 2019

Stephen Cobeldick
on 24 Jul 2019

Sign in to comment.

Answer by Image Analyst
on 23 Jul 2019

Instead of this

if s<200

logic=1;

else

logic=0;

do this

logic = s < 200; % Just one line, not a whole if/else block.

if logic

return; % Exit out of the function entirely so s does not get altered anymore.

end

Enez Furkan Cihan
on 23 Jul 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.