I am trying to create this matrix ; How can i do this using for loops or without loops?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Voss
il 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Blue in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!