필터 지우기
필터 지우기

how to generate a matrix in a nested looped

조회 수: 3 (최근 30일)
yesenia Arzate-andujo
yesenia Arzate-andujo 2020년 4월 8일
답변: Prasad Reddy 2020년 4월 26일
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