How to create a vector of increasing and decreasing increments with linspace?
Show older comments
I need to create a vector b = 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1 (19 elements) using linspace function. How would I create this with only one command?
4 Comments
Adam Danz
on 14 Sep 2019
Why not just
b = [1:10,9:-1:1]
?
Rik
on 14 Sep 2019
This sounds like a strange requirement. What is the full text of this homework assignment?
Rahul Kumar
on 14 Sep 2019
b = [linspace(1,10,10) linspace(9,1,9)]
John D'Errico
on 14 Sep 2019
Clearly homework, because requiring the use of linspace is artificial. And there is no need to use linspace either. You don't even need to use brackets, if you want to be tricky. For example...
10 - abs(-9:9)
Or, perhaps this one?
1 + abs(mod(0:18,10) - 8*floor((0:18)/10))
Not at all hard to find multiple ways to do this homework problem. That linspace was not used in these ways seems irrelevant. And really, who needs linspace anyway? Unless it is for homework.
Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!