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)

采纳的回答

Walter Roberson
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
Walter Roberson 2018-1-26
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
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 个评论
Prabha Kumaresan
Prabha Kumaresan 2018-1-24
编辑:Walter Roberson 2018-1-24
Calling function--
% function [E,E_part]=cluster_rows(G,D,rows)
function [E,E_part,P_part,U_part,V_part]=cluster_rows4(G,D,rows)
global t
global r
global q
%extract the parts of the matrices
G_part=G(rows,:);
D_part=D(rows,:);
%sum along the the vertical axis to get indices for the non-0 columns
non_0=sum(D_part);
%Repeat the vector back to the same size as the partial matrix. It will be
%converted to a logical later on.
non_0=repmat(non_0,length(rows),1);
%create a copy of B, as that is the basis for C
E=D;
E_part=D_part;
%for all non-zero columns, replace the 0 positions with the values from A
E_part(non_0 & E_part==0)=G_part(non_0 & E_part==0)
% D_part(non_0 & D_part==0)=G_part(non_0 & D_part==0)
%paste the edited partial matrix back
% D(rows,:)=D_part
E(rows,:)=E_part;
P_part = rand(size(E_part)) .* (E_part ~= 0);
U_part=sort(E_part,'descend');
V_part=sort(P_part);
EP{t,r,q}=E_part;
PP{t,r,q}=P_part;
UP{t,r,q}=U_part;
VP{t,r,q}=V_part;
end
Prabha Kumaresan
Prabha Kumaresan 2018-1-24
The above one was the function which I used in the main code.Now could you please help me to check the throughput1 size.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by