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!