Create a square matrix with a nested loop

4 次查看(过去 30 天)
-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 个评论
Mehmet ali Karatas
Mehmet ali Karatas 2020-8-31
I tried but I still couldn't. I will be glad if you help.
madhan ravi
madhan ravi 2020-8-31
Post what you have tried, even if it has mistakes.

请先登录,再进行评论。

回答(2 个)

KSSV
KSSV 2020-8-31
编辑:KSSV 2020-8-31
A = zeros(4) ;
A(1,:) = -20:2:-14 ;
A(2,:) = -12:2:-6 ;
A(3,:) = -4:2:2 ;
A(4,:) = 4:2:10 ;

Clement Val
Clement Val 2020-8-31
编辑:Clement Val 2020-8-31
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?

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by