Event base simulation in matlab
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Aftab Ahmed Khan
2014-6-11
编辑:Aftab Ahmed Khan
2014-6-11
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');
Aftab Ahmed Khan
2014-6-11
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.
José-Luis
2014-6-11
Ok, but what are the conditions?
if first_col = what then third_column what?
if second_col = what then third_column what?
Aftab Ahmed Khan
2014-6-11
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.
Aftab Ahmed Khan
2014-6-11
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.
Aftab Ahmed Khan
2014-6-11
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.
Aftab Ahmed Khan
2014-6-11
Actually, i don't know how to do time based simulation in which we look at the simulation time.
Aftab Ahmed Khan
2014-6-11
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.
José-Luis
2014-6-11
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.
Aftab Ahmed Khan
2014-6-11
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.
Abhishek M
2014-6-12
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
Aftab Ahmed Khan
2014-6-12
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.
Abhishek M
2014-6-12
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??
Aftab Ahmed Khan
2014-6-12
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
2014-6-12
编辑:Abhishek M
2014-6-12
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??
Aftab Ahmed Khan
2014-6-12
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.
Aftab Ahmed Khan
2014-6-12
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.
Aftab Ahmed Khan
2014-6-12
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.
Aftab Ahmed Khan
2014-6-12
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
Aftab Ahmed Khan
2014-6-12
Hi, I just managed what i wanted to achieve. Thank you so much dear. i really appreciate your time and support. Take care......
Abhishek M
2014-6-13
Cool.. I saw your recent query. That question seems to be more clear than this. Anyways good to know you got your solution.
Cheers.
采纳的回答
Abhishek M
2014-6-11
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 个评论
Aftab Ahmed Khan
2014-6-11
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.
Aftab Ahmed Khan
2014-6-11
编辑:Aftab Ahmed Khan
2014-6-11
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?
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Beamforming 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)