create special matrix without use from for loop

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 24 May 2015
For any given T,
a = zeros(T,2*T);
a(1:2*T+1:end) = 1;
a(T+1:2*T+1:end) = -1;

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!