How to program a nested loop with a matrix?

Nested loop: Write a program to create a 4x4 matrix for which each entry is computed as follows: A(i,j) = 2i-j.

댓글 수: 2

Greg
Greg 2018년 3월 24일
What have you tried?
We aren't here to do your homework for you.
Rose
Rose 2018년 3월 24일
Sorry Greg, I didn't want to give the impression that I'm not trying! I'm just a bit confused about exactly what this question is asking. Any thoughts to clarify the procedure (not the exact code) would be appreciated :)

댓글을 달려면 로그인하십시오.

 채택된 답변

Abraham Boayue
Abraham Boayue 2018년 3월 24일

0 개 추천

Hey Rose, since the size of your matrix is going to be 4x4, you will need to do the following to achieve your goal.
1. Initialize A to a 4x4 zero matrix since that's how much space you need.
N = 4; this is the number of rows
M = 4; number of columns
A = zeros(N,M); % 4x4 matrix
2. write your double for loops
for i = 1 : N
for j = 1: M
write your code here (It will be just a single line code)
read about how for loop works, it is one of the basis of programming.
end
end

댓글 수: 2

Rose
Rose 2018년 3월 24일
Thank you so much, this helped a lot!
You are welcome, feel free to to ask if you get stuck.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adnan  Haider
Adnan Haider 2021년 12월 1일

0 개 추천

%% how to write a table in matlab

카테고리

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

질문:

2018년 3월 24일

답변:

2021년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by