Create a square matrix with a nested loop

4 vues (au cours des 30 derniers jours)
Mehmet ali Karatas
Mehmet ali Karatas le 31 Août 2020
Modifié(e) : Clement Val le 31 Août 2020
-20 -18 -16 -14
-12 -10 -8 -6
-4 -2 0 2
4 6 10 12
can you create it with a loop inside
  3 commentaires
Mehmet ali Karatas
Mehmet ali Karatas le 31 Août 2020
I tried but I still couldn't. I will be glad if you help.
madhan ravi
madhan ravi le 31 Août 2020
Post what you have tried, even if it has mistakes.

Connectez-vous pour commenter.

Réponses (2)

KSSV
KSSV le 31 Août 2020
Modifié(e) : KSSV le 31 Août 2020
A = zeros(4) ;
A(1,:) = -20:2:-14 ;
A(2,:) = -12:2:-6 ;
A(3,:) = -4:2:2 ;
A(4,:) = 4:2:10 ;
  1 commentaire
Mehmet ali Karatas
Mehmet ali Karatas le 31 Août 2020
it should form this square matrix with nested loops

Connectez-vous pour commenter.


Clement Val
Clement Val le 31 Août 2020
Modifié(e) : Clement Val le 31 Août 2020
reshape([-20:2:10], 4, 4)'
Just (half) kidding.
You know how to do a loop?
You know how to index in a 2 dim array?
You know how to increment another variable by two?

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