How to create a vector of increasing and decreasing increments with linspace?

7 ビュー (過去 30 日間)
Noriko Kawasaki
Noriko Kawasaki 2019 年 9 月 14 日
コメント済み: John D'Errico 2019 年 9 月 14 日
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 件のコメント
Rahul Kumar
Rahul Kumar 2019 年 9 月 14 日
b = [linspace(1,10,10) linspace(9,1,9)]
John D'Errico
John D'Errico 2019 年 9 月 14 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by