Event base simulation in matlab

Hi, I don't know how to do event based simulation in matlab. Just need a start for it, this question is a start part of my bigger task.
i have this,
arrival_departure_frequency =
0.0000 5.9489 0
0.0000 6.6353 0
0.0001 6.9292 0
0.0001 6.9361 0
0.0001 7.2979 0
0.0001 7.7989 0
0.0002 7.9419 0
0.0002 8.8358 0
0.0002 8.8383 0
0.0002 9.0600 0
First column is my event_arrivals and the 2nd column is event_departure. I want to change the value of third column from 0 to 1 when the simulation is in between arrival time and the departure time.
Once the event_departure arrives it again back set to O. Thank you so much.

27 Commenti

I am not sure I follow. What are the values that trigger the change?
Hi,
Any value in the first column will trigger the change in the third column(change its value from 0 to 1 upon arrival and from 1 to 0 up on file departure).
Until now i did this, i don't know how to release the channel (i.e from 1 to 0).
for i =1:10
timenow = event_arrivals(i);
no_channels = find(BS_channeltable == 0);
first_available = min(no_channels);
%%Allocating the Channel on the file arrival
if timenow == (event_arrivals(i))&&(first_available ~=0)
BS_channeltable(first_available) = 1;
fprintf(fid,'Frequency is assigned.\n');
Releasing the channel on file departure
elseif timenow == event_departures(i)
release_channel = find(BS_channeltable==1);
last_occuped = max(release_channel);
BS_channeltable(last_occuped) = 0;
fprintf(fid,'Frequency is released.\n');
Will trigger a change depending on what? What are the conditions?
I only want to change the values in the third column from 0 to 1 according to the first column values and from 1 to 0 according to the second column values.
Ok, but what are the conditions?
if first_col = what then third_column what?
if second_col = what then third_column what?
sorry,if i look a bit dump here.
if now_time = 0.0000 then change the value in the third column from 0 to 1
and so on.....
if now_time = 5.9489 then change the value in the third column from 1 to 0.
Similarly for the remaining 9 events as well.
for 0 to 1, the values in the first column are the trigger time while for 1 to 0 the values in the second column are the trigger times.
And where do you get now_time from?
This is my simulation time, when it equals to first event arrival time it changes value in the third column from 0 to 1 and when its value equal to the first event departure time, it changes that value back from 1 to 0.
Actually, i don't know how to do time based simulation in which we look at the simulation time.
I am sorry, I don't understand what you want.
Hi, can you help me like how to do a event based simulation in Matlab. Even if it is a very simple example. Like there are some arrivals events and you do something very simple when that time arrives, may be change 0 to 1 or vice versa in another matrix.
This sounds like something for Simulink.
I don't understand what your _arrival_events_are or where they come from. The rest of your problem sounds like it could be solved by two nested if's.
Let me explain it further, if it helps,
As you see in the question at time = 0.0000 sec (first value) the file arrives and at time t = 5.9489 sec it departs, so for this duration of time i want the value in the third column which is first at 0 will turn to 1 and when time passes 5.9489 it again turns back to 0. Similarly for the rest of the remaining 9 events to follow.
And how do you measure time? You could look into a timer object.
doc timer
Are the rows which you provided are of different iterations??
Are these rows related to each other or how is it?? Can you please give some details about it??
0.0000 5.9489 0
0.0000 6.6353 0
Let me explain it to you,
Let say i want to run my simulation for a time of 20 seconds. So when that simulation time equals to the first value (0.0000) of the first column, it changes 0 to 1 in the third column and so on.
And when the simulation time equals to the first value in the second column (5.9489) it changes back the value in the third column from 1 to 0 back.
I guess the 1st 2 columns are inputs and the 3rd column is output{0/1}. What are the other rows, are they different probabilities of inputs?? and are these rows related to each other??
Yes they are, like at any value of the first column the value in the third column changes and again when time equals to any value in the second column the value in the third column changes back.
Abhishek M
Abhishek M il 12 Giu 2014
Modificato: Abhishek M il 12 Giu 2014
will that work aftab??
for example consider these 2 rows
0.0000 6.6353 0
0.0001 6.9292 0
until 0.000 to 6.6353 value will be 1 and what will be the value between 6.6353 to 6.9292. Or else does your input resets after each row and start again with the next row??
Since 6.6353 and 6.9292 having different output location, so at 6.6353 its corresponding 1 will change back to 0 and at 6.9292 its corresponding 1 will change back to 0 too.
Different output locations??? What does that mean??
i mean, that the values in the third columns are reserved for its corresponding values in the other two columns having the same row number.
Hi Abhishek, i am working on the same task right now will share may code with you shortly may be that will help you to understand what i want to achieve here.
Hi Abhi, This is what i have done and it work so for (little bit). The problem i have now is in the last line of this code in the arrivals variable. I want to remove only the first value in the arrivals variable, like one by one during each while loop execution but it doesn't behave so such.
tmax = 30;
nowtime = 0;
A = 2;
D = 2;
while nowtime < tmax
nowtime = min(arrivals);
available_channels = find((BS_channeltable)==0);
first_available = min(available_channels);
BS_channeltable(first_available) = 1;
fprintf(fid,'\n One channel is allocated.');
arrivals = arrivals(A:end);
A = A+1;
end
Hi, I just managed what i wanted to achieve. Thank you so much dear. i really appreciate your time and support. Take care......
Cool.. I saw your recent query. That question seems to be more clear than this. Anyways good to know you got your solution.
Cheers.

Accedi per commentare.

 Risposta accettata

Abhishek M
Abhishek M il 11 Giu 2014

0 voti

Hi Aftab, I insist you to use stateflow for this logic. You can create your events and trigger the output based on your logic.

3 Commenti

Hi Abhishek, i don't know how to create stateflow in Matlab.
Hello, i have tried up to this point but how can i introduce the departure time with it.
for i =1:10
timenow = event_arrivals(i);
no_channels = find(BS_channeltable == 0);
first_available = min(no_channels);
if timenow == (event_arrivals(i))&& (first_available ~=0)
BS_channeltable(first_available)=1;
end
end
Please help me with it.
Hi,
I have managed up to this point but how can i release the channel from it as it will never reach to the departure time of the files.
for i =1:10
timenow = event_arrivals(i);
no_channels = find(BS_channeltable == 0);
first_available = min(no_channels);
%%Allocating the Channel on the file arrival
if timenow == (event_arrivals(i))&&(first_available ~=0)
BS_channeltable(first_available) = 1;
fprintf(fid,'Frequency is assigned.\n');
Releasing the channel on file departure
elseif timenow == event_departures(i)
release_channel = find(BS_channeltable==1);
last_occuped = max(release_channel);
BS_channeltable(last_occuped) = 0;
fprintf(fid,'Frequency is released.\n');
end
end
and how can i get my simulation to the departure time?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by