Defining a time varying function
    12 次查看(过去 30 天)
  
       显示 更早的评论
    
I'd like to create a function that will output a value of  a (e.g. a = 10) for time  < t0 and value equal to b at time > t0.
Any suggestions on how to create such a function in MATLAB will be helpful
0 个评论
回答(1 个)
  Adam
      
      
 2020-2-25
        
      编辑:Adam
      
      
 2020-2-25
  
      if t < t0
    result = a;
else
    result = b;
end
gives what you want for this simple case, provided t0, a, b and t are all passed into the function or defined at the top of the function.  If it where more complicated I might suggest other methods but a simple binary threshold output works fine with an if statement.
2 个评论
  Adam
      
      
 2020-2-26
				You'd need to rephrase the question to more precisely ask what you want in that case.  To fulfill what you asked in the question then including a reasult of mean( [a, b] ) for t == t0 would be the only approach that is slightly less discontinuous.
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!