help for matrix manipulation with loop
1 次查看(过去 30 天)
显示 更早的评论
%for n=i (i is variable, taken 6 this example), I need to create the below matrix % i numbers rows and (i-3) numbers columns need to be created as follow;
j=[0;0;0;1;0;0]
m=[0;0;0;0;1;0]
k=[0;0;0;0;0;1]
created_matrix=[j,m,k]
%I need to write a loop w.r.t. the i variable for creating this matrix.
1 个评论
Stephen23
2015-6-4
Using vectorized code is much neater, faster and more robust than using loops. Learn to write vectorized code and suddenly MATLAB becomes a powerful tool for you to use...
采纳的回答
更多回答(1 个)
Andrei Bobrov
2015-6-4
编辑:Andrei Bobrov
2015-6-4
n= 3;
out = [zeros(n);eye(n)];
with loop
out = zeros(2*n,n);
for jj = 1:n
out(jj+3,jj) = 1;
end
0 个评论
另请参阅
类别
在 Help Center 和 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!