How can i create an n x m matrix that the value of each element is the first row is the number of the column?

조회 수: 20 (최근 30일)
How can I write a program in a script file that creates a n x m matrix that the value of the each element in the first row is the number of the column? The value of each element in the first column is the number of the row. The rest of the elements each has a value equal to the sum of 2 times of the element above it and the element to the left.

채택된 답변

KSSV
KSSV 2016년 10월 26일
clc; clear all ;
n = 5 ;
m = 7 ;
M = zeros(n,m) ;
M(1,:) = 1:m ;
M(:,1) = 1:n ;
for i = 2:n
for j = 2:m
M(i,j) = 2*(M(i-1,j)+M(i,j-1)) ;
end
end
  댓글 수: 4
Diprit
Diprit 2022년 11월 20일
clc
n = 3
m = 3
M = zeros(n,m)
M(1,:) = 1:m
M(:,1) = 1:n
for i = 2:n
for j = 2:m
M(i,j) = M(i-1,j)+M(i,j-1)
end
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by