Filter löschen
Filter löschen

how to generate a matrix in a nested looped

3 Ansichten (letzte 30 Tage)
yesenia Arzate-andujo
yesenia Arzate-andujo am 8 Apr. 2020
Beantwortet: Prasad Reddy am 26 Apr. 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

Antworten (1)

Prasad Reddy
Prasad Reddy am 26 Apr. 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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by