how to generate a matrix in a nested looped

1 次查看(过去 30 天)
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

回答(1 个)

Prasad Reddy
Prasad Reddy 2020-4-26
% 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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by