Could anyone help me to check with the following code

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.

 Respuesta aceptada

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 comentarios

could you please tell me how it can be solved such that the code executes without error
Since the code executes to error at the moment, you can be fairly sure that the correction is not
unused_rows = 1 : N_UE(1);
Perhaps it should be some other N_UE entry.
Prabha Kumaresan
Prabha Kumaresan el 19 de En. de 2018
Editada: Walter Roberson el 19 de En. de 2018
i tried with
unused_rows = 1 : N_UE(t)
and i replaced the section
EP{q}(t,r)=E_part
PP{q}(t,r)=P_part
UP{q}(t,r)=U_part
VP{q}(t,r)=V_part
All_EP(t,r)=[cat(1, EP(t,r){:})]
All_PP(t,r)=[cat(1, PP(t,r){:})]
All_UP(t,r)=[cat(1, UP(t,r){:})]
All_VP(t,r)=[cat(1, VP(t,r){:})]
Error: File: Line: 35 Column: 6
()-indexing must appear last in an index expression.
but still i am getting
Error: File: Line: 43 Column: 22
()-indexing must appear last in an index expression.
To fix the "()-indexing must apepar last in the index expression", change
All_EP(t,r)=[cat(1, EP(t,r){:})]
to
temp = EP(t,r);
All_EP(t,r)=[cat(1, temp{:})]
This will solve the syntax problem with using {} after (). It will not, however, repair the other problems in the code.
After changing it still gives the error Undefined function or variable 't'.
Error in cluster_rows7 (line 25) EP{q}(t,r)=E_part
Error in seven (line 34) [E,E_part,P_part,U_part,V_part]=cluster_rows7(G,D,rows);
could you tell me is there any other way to overcome it.
Pass t and r into cluster_rows7 as additional parameters and make sure that you include them on the function line for cluster_rows7
do you want me to do in the following way [E,E_part,P_part,U_part,V_part]=cluster_rows7(G,D,rows,t,r)
Yes. And remember to adjust the function declaration for the function to add those two parameters.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by