How solve this problem in Matlab
Show older comments
How can I write a program in a script file that creates and 𝑛 × 𝑚 matrix with elements that have the following values. The value of 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 the element above it and the element to the left.
1 Comment
Yeachan Choi
on 24 Mar 2022
Edited: Yeachan Choi
on 24 Mar 2022
Accepted Answer
More Answers (1)
David Goodmanson
on 25 Mar 2022
Hi Davide,
here is a method that uses one for loop instead of two:
n = 5
m = 6
V = zeros(n,m);
V(:,1) = 1:n;
for k = 2:m
V(:,k) = cumsum(V(:,k-1)) +1;
end
V
V =
1 2 3 4 5 6
2 4 7 11 16 22
3 7 14 25 41 63
4 11 25 50 91 154
5 16 41 91 182 336
Categories
Find more on Startup and Shutdown 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!