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

7 次查看(过去 30 天)
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 个评论
Tarun Cousik
Tarun Cousik 2019-3-13
编辑:Tarun Cousik 2019-3-13
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 2019-3-14
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by