How to program a nested loop with a matrix?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Rose
le 24 Mar 2018
Réponse apportée : Adnan Haider
le 1 Déc 2021
Nested loop: Write a program to create a 4x4 matrix for which each entry is computed as follows: A(i,j) = 2i-j.
2 commentaires
Réponse acceptée
Abraham Boayue
le 24 Mar 2018
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 commentaires
Plus de réponses (1)
Voir également
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!