help for matrix manipulation with loop
3 ビュー (過去 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!