for loop and else-if-elseif loo

1 次查看(过去 30 天)
kevin piaget
kevin piaget 2012-11-25
i would like to create an matrix(m,n) using for loop and else-if-elseif
  • ask user to input m,n
  • in the matrix:the value of the element in the first row is the number of the column.the vaue of the element in the first column is the number of the row.the rest of element are equal to the sum of the element above them and the element in the left.
i get this
m=input('number of rows')
n=input('number of column')
a=ones(m,n)
for i=2:m
for j=2:n
a(i,j)=a(i-1,j)+a(i,j-1)
end
end
my problem is concerning the elemt in the first row and column

回答(1 个)

Walter Roberson
Walter Roberson 2012-11-25
Hint:
a = zeros(m,n);
a(:,1) = 1:m;

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by