Clear Filters
Clear Filters

help for matrix manipulation with loop

2 views (last 30 days)
%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;
%I need to write a loop w.r.t. the i variable for creating this matrix.
  1 Comment
Stephen23 on 4 Jun 2015
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...

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 4 Jun 2015

More Answers (1)

Andrei Bobrov
Andrei Bobrov on 4 Jun 2015
Edited: Andrei Bobrov on 4 Jun 2015
n= 3;
out = [zeros(n);eye(n)];
with loop
out = zeros(2*n,n);
for jj = 1:n
out(jj+3,jj) = 1;


Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!