Clear Filters
Clear Filters

how to generate a matrix in a nested looped

3 views (last 30 days)
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

Answers (1)

Prasad Reddy
Prasad Reddy on 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

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!