필터 지우기
필터 지우기

help for matrix manipulation with loop

조회 수: 1 (최근 30일)
sermet
sermet 2015년 6월 4일
댓글: Stephen23 2015년 6월 4일
%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
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...

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 4일
[zeros(3);eye(3)]

추가 답변 (1개)

Andrei Bobrov
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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by