could anyone tell me how to solve the issue
1 次查看(过去 30 天)
显示 更早的评论
If i run the following code
code:
for v =1:size(All_VP,2)
for u =1:size(All_UP,1)
throughput1(u,v)=(Bmax.*log2(1+(((All_UP(u,v)).*(All_VP(u,v))/(noise+sum(All_VP(1:u-1,v)).*All_UP(u,v))))))
end
end
I am getting the size of the throughput1(u,v) as 22x40 double,which should be 20x40 double.
where
size(All_VP,2) is 40
size(All_UP,1) is 20
size of (ALL_UP(u,v)) is 20x40 double,
size of (All_VP(u,v)) is 20x40 double,
size of (All_VP(1:u-1,v)) is 20x40 double.
Could anyone help me to overcome the size of the throughput1(u,v)
0 个评论
采纳的回答
Walter Roberson
2018-1-24
Consider your line
N_UE_rows=ceil(sqrt(randi([2,numel(unused_rows)])));
Together with your latest sample code that does [3 6] and [12 15].
With the randi starting at 2, sqrt(2) is 1.4-ish, ceil() of that is 2. So you never allocate fewer than 2 at a time.
With 3 as the maximum, ceil(sqrt(2)) -> 2 and ceil(sqrt(3)) -> 2 are the only possibilities, and the line after that one that tests the random number plus 1 against the limit will kick in pushing the value to 3. So with 3, you always allocate all 3 the first time through. Only the q=1 slot of EP{t,r,q}=E_part will be written into for this case.
With 6 as the maximum, the random choices 2, 3, and 4 map into 2, and the random choices 5 and 6 map into 3 (their square roots are between 2 and 3 and the ceil drives them to 3). So about 3/5 = 60 percent of the time you allocate 2 rows initially. When you do so that reduces the available rows to 4 and the next round sqrt(2), sqrt(3), sqrt(4) all map to 2, so the next round would be 2 as well, and that would leave 2 for the third round -- so 3/5 of the time you use up to slot q=3 of EP{t,r,q}=E_part, packing them as 2, 2, 2.
The other 2/5 = 40 percent of the time, you allocate 3 rows initially. When you do so, that reduces the available rows to 3, and the next round sqrt(2), sqrt(3) map to 2 but the special +1 case will cause it to grab the full 3 remaining. So if 3 are allocated the first time, then you use up to slot q=2 of EP{t,r,q}=E_part, packing them as 3, 3.
But when you pack as 3, 3, you do not erase any existing q=3 cell that had the 2 put into it from a 2, 2, 2 packing. So if you previously had a 2, 2, 2 packing, then after the 3, 3 packing, the cells have 3, 3 (just written) and then a left-over which is 3, 3, 2 = 8 -- two more than what you are expecting.
Now, you do effectively erase throughput1 each time through (you allocate zeros but you allocate less spaces than will be written to.) So this throughput1 that is 2 rows too large will not affect the next iteration. But... every once in a while, the 3, 3, 2 packing happens on the last iteration you do, the one for the maximum it, t and r. And when it does, you see throughput1 as being 2 rows too large after the end of the routine.
With larger array sizes, the number of extra rows could end up larger -- but you are biasing the random integer generation towards lower values, so the extra will tend to be 2 when it is there at all. Could be more though.
6 个评论
Walter Roberson
2018-1-26
Not in the code you posted in https://www.mathworks.com/matlabcentral/answers/378314-could-anyone-tell-me-how-to-solve-the-issue#comment_527885 . In that code, you have
EP{t,r,q}=E_part
PP{t,r,q}=P_part;
UP{t,r,q}=U_part;
VP{t,r,q}=V_part;
within a loop, but you never initialized EP or PP or UP or VP in the code. You need to add
EP = {}; PP = {}; UP = {}; VP = {};
just before your q=1; line.
更多回答(1 个)
KSSV
2018-1-22
All_UP = rand(20,40) ;
All_VP = rand(20,40) ;
Bmax = rand ;
noise = rand ;
% All_VP(1:u-1,v)) is 20x40 double.
throughput1=zeros(20,40) ;
for v =1:size(All_VP,2)
for u =1:size(All_UP,1)
throughput1(u,v)=(Bmax.*log2(1+(((All_UP(u,v)).*(All_VP(u,v))/(noise+sum(All_VP(1:u-1,v)).*All_UP(u,v))))));
end
end
with the sizes you specified.......what you get is 20X40 matrix only.
11 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!