Fill an array after a for loop
Afficher commentaires plus anciens
Hi, given the following code
v = [1 2 3 4 1];
P = unique(perms(v),'rows');
nraw = size (P,1);
G=zeros()
for i=1:nraw
x=P(i,:)
n=length(x);
f = zeros(1,n);
for k = 1:n
if x(k) == 1
f(1,k) = 1;
elseif x(k)==2
f(1,k) = 2;
elseif x(k)==3
f(1,k)= 3;
elseif x(k)==4
f(1,k) = 4;
elseif x(k)==5
f(1,k)= 1;
end
end
G(i,:)=x(i,:)
end
I would like to fill the matrix G with every raw x that undergoes through the for cycle.
but I receive the followign error:
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the
right side is 1-by-5.
Error in
G(i,:)=x(i,:)
Does someone know where the problem is? and why is not working?
Thanks
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!