Fill an array after a for loop
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!