Create a square matrix with a nested loop

-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

madhan ravi
madhan ravi 2020년 8월 31일
Huh, expecting others to write your homework? Did you try anything at all?
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일

0 개 추천

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일

0 개 추천

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?

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 8월 31일

편집:

2020년 8월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by