Using variable as limiting index counts one less.

Hello fellow Mathworkers,
i encountered a strange behavior when reading from an array:
Let's say my array is A = zeros(1,100000) and i want B = A(1:50000) and C = A(50001:100000)
B and C are both 1x50000 double. That's what i want.
But when reading it like B = A(start:stop) and start = 1 and stop = 50000, B will be only 1x49999 double.
Is this a bug or am i missing something?
Thanks in advance!

4 件のコメント

Awais Saeed
Awais Saeed 2021 年 8 月 21 日
編集済み: Awais Saeed 2021 年 8 月 21 日
I am getting B = A(start:stop) = 1x50000 with start = 1 and stop = 50000.
Paul Werner
Paul Werner 2021 年 8 月 21 日
Propably i missed something. When typing it direktly in the command window, it works just fine. When using stop = 1/2e-5 my problem occures. So using round(stop) works for me.
Thank's for the sanity check!
Paul Werner
Paul Werner 2021 年 8 月 21 日
Should i close the question or is this useful for others?
Stephen23
Stephen23 2021 年 8 月 21 日
編集済み: Stephen23 2021 年 8 月 21 日
A = zeros(1,100000);
start = 1;
stop = 50000;
B = A(start:stop)
B = 1×50000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
"Propably i missed something ... When using stop = 1/2e-5 my problem occures."
You did not take into account the behavior of binary floating point numbers.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2019a

タグ

質問済み:

2021 年 8 月 21 日

編集済み:

2021 年 8 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by