フィルターのクリア

How can I increase my vector by increments of 100 but end on 558?

1 回表示 (過去 30 日間)
Clare Ferguson
Clare Ferguson 2017 年 9 月 24 日
編集済み: Stephen23 2017 年 9 月 24 日
I need to create a vector that starts at 0, increases by 100 each time but ends at 558.
The following outlines my function:
x_int = 0:100:558
This works except it only calculates up to 500 and not 558.
  1 件のコメント
Stephen23
Stephen23 2017 年 9 月 24 日
編集済み: Stephen23 2017 年 9 月 24 日
@Clare Ferguson: can you please edit your question and show the expected output.
Why did you tag your question with "linear interpolation"? I don't see the relevance.

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

採用された回答

Stephen23
Stephen23 2017 年 9 月 24 日
編集済み: Stephen23 2017 年 9 月 24 日
Like this?:
>> val = 558;
>> vec = 0:100:val;
>> vec = [vec,val(vec(end)~=val)]
vec =
0 100 200 300 400 500 558
Doing this over two lines allows appending that value only if it is not already the last value in the vector, e.g.:
>> val = 500;
>> vec = 0:100:val;
>> vec = [vec,val(vec(end)~=val)]
vec =
0 100 200 300 400 500

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by