I am trying to create this matrix ; How can i do this using for loops or without loops?
2 views (last 30 days)
Show older comments
A=[1 1 1 0 0 0 0 0 0; 1 1 1 1 1 1 0 0 0 ; 1 1 1 1 1 1 1 1 1 ];
0 Comments
Accepted Answer
Voss
on 25 Mar 2022
Here's one way without loops (just typing the matrix out):
A=[1 1 1 0 0 0 0 0 0; 1 1 1 1 1 1 0 0 0 ; 1 1 1 1 1 1 1 1 1 ];
But I guess that's not what you're looking for.
Maybe this instead:
N = 3;
A_1 = repelem(cummax(eye(N)),1,N)
isequal(A,A_1) % check
Or this:
A_2 = zeros(N,N^2);
for ii = 1:N
A_2(ii,1:N*ii) = 1;
end
A_2
isequal(A,A_2) % check
2 Comments
More Answers (0)
See Also
Categories
Find more on Blue 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!