Loop in a Function

1 回表示 (過去 30 日間)
Brittany Isbister
Brittany Isbister 2021 年 2 月 12 日
回答済み: Reshma Nerella 2021 年 2 月 19 日
Hi All,
I'm suppose to make a function that has the inputs lambda and twin with the outputs taus and tspike. The twin value is the time window for simulation starting at zero. Theres also a U value which is determined by using the rand function. The function needs to loop to get values for tau using the equation in the code and the corresponding tspike times. I made the function, but I'm not sure how to put in the twin or how to loop. Thanks for all the help in advance!
function [taus,tspike]=simulateSpikes(lambda,twin);% function with the inputs
U=rand;
while twin<= % making that it'll only run for the value and less
taus=-ln(U)/lambda; % equation for taus
tspike=(0;twin)% getting the tspike values between 0 and twin
end
  1 件のコメント
Rik
Rik 2021 年 2 月 12 日
Have you considered doing a basic Matlab tutorial? I would suggest Onramp.

サインインしてコメントする。

回答 (1 件)

Reshma Nerella
Reshma Nerella 2021 年 2 月 19 日
Hi,
If you want to get different value of taus for each iteration consider placing
U=rand;
in the loop. Else it will be same for every iteration.
If you want to store all the values of taus for evry iteration, consider using arrays.
Consider going through the documentation page of while, to understand how it works.
Hope this helps!

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by