How do I Pass Function Parameters Which Get Updated Within A Loop

2 views (last 30 days)
Hi,
Im posting the very high level crux of the problem I'm facing. I've bolded the part whic has left me stratching my head and would like inputs
Keywords: Master Code (code Im executing directly), function1- used by master code to obtain some parameters
Master code
Calls function1
Uses output of function1(will be an interger) to plot/shift a predetermined function
_____________________________________________________________________
function1
for = -x:1:x
need to return (x) and then proceed with the rest of the loop
rest of the loop does some other cool stuff
end
Also, because the loop return variable retruns a different value everytime, the master code needs to be able to monitor the change in value of parameter1 and reflect changes to its output after it happens.
From what I understand, a simple return(x) in function1's loop would return the value and skip the remaining part of the loop (which is a big no-no). So, thats not the way to go, right?.
I thought I'd be "smart" and make paramter 'x' as one of the output variables of function1 but nothing happened; should that be the case?
Any suggestions/comments? Also, a more fundamental question, is there a name for what I'm trying to do here (apart from cerebral defenstration)?
  3 Comments
Tarun Cousik
Tarun Cousik on 13 Mar 2019
Edited: Tarun Cousik on 13 Mar 2019
Yes! Thats what I ended up doing! Thanks Alex! - I will accept this as a answer if you choose to submit this as one.
On a side note, I am curious, do you know if something like this( "return value and continue loop") is possible? If there is, what is called?
Alex Mcaulley
Alex Mcaulley on 14 Mar 2019
I don't know how it is called (if it has name), but you can do it using global variables and while loops to wait for the result of the other function (for example), but it is not recommendable.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!