Could anyone help me to check with the following code
1 view (last 30 days)
Show older comments
Prabha Kumaresan
on 19 Jan 2018
Commented: Walter Roberson
on 19 Jan 2018
code:
global q
N_UE=[10 20 30 40 50];
N_SC=[60 70 80 90 100];
iwant = cell(length(N_UE),1);
for t= 1:length(N_UE)
for r= 1:length(N_SC)
G=rand(N_UE(t),N_SC(r));
N_SC_=ceil(N_SC(r)/N_UE(t));%round up to nearest multiple
C=repmat(diag(1:N_UE(t)),1,N_SC_);
iwant{t}=C(:,1:N_SC(r));%crop back to only needed cols
D = iwant{t};
unused_rows=1:N_UE;
q=1
while ~isempty(unused_rows)
N_UE_rows=ceil(sqrt(randi([2,numel(unused_rows)])));
if (N_UE_rows+1)==numel(unused_rows)
N_UE_rows=numel(unused_rows);
end
rows=unused_rows(randsample(length(unused_rows),N_UE_rows));
[~,idx]=find(ismember(unused_rows,rows));
unused_rows(idx)=[];
[E,E_part,P_part,U_part,V_part]=cluster_rows(G,D,rows);
EP{q}=E_part
PP{q}=P_part
UP{q}=U_part
VP{q}=V_part
q=q+1
end
All_EP=[cat(1, EP{:})]
All_PP=[cat(1, PP{:})]
All_UP=[cat(1, UP{:})]
All_VP=[cat(1, VP{:})]
end
end
-------------------------- ----------------------------
% function [E,E_part]=cluster_rows(G,D,rows)
function [E,E_part,P_part,U_part,V_part]=cluster_rows(G,D,rows)
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{q}=E_part
PP{q}=P_part
UP{q}=U_part
VP{q}=V_part
end
If i run the code i am getting
Error using cat
Dimensions of matrices being concatenated are
not consistent.
Error in (line 43)
All_EP=[cat(1, EP{:})]
could anyone help to overcome it.
0 Comments
Accepted Answer
Walter Roberson
on 19 Jan 2018
You have
unused_rows=1:N_UE;
but N_UE is a vector. The right hand side of a colon expression should always be a scalar. MATLAB does not give a warning or error when you use a vector on the right side, but it will ignore everything except for the first element.
8 Comments
Walter Roberson
on 19 Jan 2018
Yes. And remember to adjust the function declaration for the function to add those two parameters.
More Answers (0)
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!