Effacer les filtres
Effacer les filtres

Can someone help with a nested for loop question...

2 vues (au cours des 30 derniers jours)
Mohammed Safwat
Mohammed Safwat le 12 Déc 2017
Modifié(e) : Andrei Bobrov le 12 Déc 2017
This is the problem: Using nested loops, produce a 3 by 3 (square) matrix A. The matrix should look like this: 0 1 2 3 4 5 6 7 8
My outcome is not coming out correctly and it's slowing my study process down when I have an exam tomorrow. I have .. i = 0; k = 0; for i = 1:3 for k = 1:3 M(i,k) = i; end end M

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 12 Déc 2017
Modifié(e) : Andrei Bobrov le 12 Déc 2017
m = 3;
M = zeros(m);
jj = (0:m-1)'*m;
for ii = 1:m
M(:,ii) = jj + ii-1;
end

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by