Simulating events of varying duration
Mostrar comentarios más antiguos
Hi there, I'm trying to simulate events of varying duration. I start with a vector of onsets (in seconds from the start of the simulated session):
onset=[23 40 67 88] etc
I then generate a list of durations (in seconds - each event is a different duration):
duration=[3 9 2 6]
I can use these to make a vector of offsets, however, what I want to end up with is a vector of all the seconds in which an event is occurring:
all=23 24 25 40 41 42 43 44 45 46 47 48 67 68 88 89 90 91 92 93
I am trying to write a loop that will do this, however can only make it work if all the durations are the same (e.g., 3 seconds). I'm really stuck - any help would be greatly appreciated. Thanks so much, Rebecca
Respuesta aceptada
Más respuestas (3)
Brian B
el 7 de Feb. de 2013
This seems to be what you are looking for:
onset=[23 40 67 88]
duration=[3 9 2 6]
all=cell2mat(arrayfun(@(a,b)a+(1:b)-1,onset,duration,'UniformOutput',0))
Youssef Khmou
el 4 de Feb. de 2013
An example :
events=zeros(1,1000);
for (t=0:1000)
if mod(t,2)==0
events(t)=a;
elseif mod(t,3)==0
events(t)=b;
elseif mod(t,7)==0
events(t)=c;
.....
end
with constants a,b,c, the onsets .
is that OK?
5 comentarios
Rebecca
el 4 de Feb. de 2013
Youssef Khmou
el 4 de Feb. de 2013
Editada: Youssef Khmou
el 4 de Feb. de 2013
hi Rebecca, based on your question : the loop is :
time start at t=0 and ends at tf=1000 seconds
if instananeous time is multiple of 2 means (2s,4s,6s,8s,10s,.....100s,....) a certain event takes place with magnitude a .
again during the loop , if t is multiple of 7 means (t=7s,14s,21s,....) an event takes place with magnitude b ( in volts, atmosphere, kelvin....)
That was an example of configuration for your goal . At the end, you will get a vector "events" that contains events in specified instants with corresponding amplitudes.
Rebecca
el 5 de Feb. de 2013
Youssef Khmou
el 5 de Feb. de 2013
Editada: Youssef Khmou
el 5 de Feb. de 2013
i need more details about your simulation, if you post the problem as it should be, it will be easy to solve it, how the events take place, randomly? give simple example from your code so as we can work on it,
Rebecca
el 7 de Feb. de 2013
Rebecca
el 7 de Feb. de 2013
0 votos
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!