create special matrix without use from for loop

i wish create several matrix with out uses from for loop
for example
j=1;
for i=2:2:(2*T)
a=zeros(1,2*T);
a(i-1)=1; a(i)=-1;
one(j,:)=a;
j=j+1;
end
that every time T Replaced different number

 채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 24일

0 개 추천

For any given T,
a = zeros(T,2*T);
a(1:2*T+1:end) = 1;
a(T+1:2*T+1:end) = -1;

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2015년 5월 24일

답변:

2015년 5월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by