- When you don't bother to try solving your own homework then you won't learn anything.
- Copying someone's work and pretending that it is your work is called plagiarism. Look it up.
Can you guys help me with my ASSIGNMENT? i just don't know how to answer it =(
3 views (last 30 days)
Show older comments
Kaye Freyssinet Abanggan
on 15 Sep 2016
Can you teach my the codes of the attached problem in the picture? I will appreciate your help. thank you. =)
2 Comments
Stephen23
on 15 Sep 2016
Accepted Answer
Stephen23
on 15 Sep 2016
Edited: Stephen23
on 15 Sep 2016
Method one: bsxfun
>> n = 5;
>> bsxfun(@plus,n:-1:0,(0:n)')
ans =
5 4 3 2 1 0
6 5 4 3 2 1
7 6 5 4 3 2
8 7 6 5 4 3
9 8 7 6 5 4
10 9 8 7 6 5
Method two: toeplitz
>> toeplitz(n:2*n,n:-1:0)
ans =
5 4 3 2 1 0
6 5 4 3 2 1
7 6 5 4 3 2
8 7 6 5 4 3
9 8 7 6 5 4
10 9 8 7 6 5
4 Comments
Stephen23
on 15 Sep 2016
Edited: Stephen23
on 15 Sep 2016
@Kaye Freyssinet Abanggan: one way would be to create two loops, one nested inside the other, and use indexing to access the element:
n = 5
out = zeros(n+1);
for row = 1:n+1
for col = 1:n+1
out(row,col) = ???
end
end
All you need is one addition and one subtraction where the ??? is and this will work. I will leave this up to you to figure out. These tutorials are an excellent way to start using MATLAB:
More Answers (0)
See Also
Categories
Find more on Data Type Identification 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!