I am trying to create this matrix ; How can i do this using for loops or without loops?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2022-3-25
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Blue 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!