Effacer les filtres
Effacer les filtres

how to generate a matrix in a nested looped

3 vues (au cours des 30 derniers jours)
yesenia Arzate-andujo
yesenia Arzate-andujo le 8 Avr 2020
Generate a matrix using nested for loops. (8 Points)
Equation: 14 + 2* (row) – 4 * (column)
Example: row 1 column 1 (1,1) = 14+2 * (1) – 4 * (1) =12
row 3 column 2 (3,3) = 14+2 * (3) – 4 * (3) = 8
I have no idea how to start this

Réponses (1)

Prasad Reddy
Prasad Reddy le 26 Avr 2020
% If you have any more doubts regardng this wuestion you can message me. hope you will unerstand this
clc
clear all
rows=input("please enter the number of rows in the required matrix"); % reading number of rows
columns=input("please ener the number of coumns in the requiredmatrix"); % reading number of columns
Required_Matrix=zeros(rows,columns); % first i am ple allocating the required matrix with zeros
for i=1:rows % itterating through each row
for j=1:columns % itterating through each column
Required_Matrix(i,j) = 14+(2*i)-(4*j); % this command fils each element by forllowing given equation
end
end
Required_Matrix

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