Counting the number of increments in a vector

3 ビュー (過去 30 日間)
Scott Banks
Scott Banks 2025 年 8 月 5 日
コメント済み: Torsten 2025 年 8 月 5 日
Hi guys,
I have vector x that goes between 0 and 7, with an increment of 0.1.
x = 0:0.1:7
I want to be able to know how many increments I have at say when x = 3, The answer is 31, but could I make use of any function in MATLAB to calculate this?
Many thanks,
Scott

採用された回答

Torsten
Torsten 2025 年 8 月 5 日
移動済み: Torsten 2025 年 8 月 5 日
x = 0:0.1:7;
numel(x(x<=3))
ans = 31
  2 件のコメント
Scott Banks
Scott Banks 2025 年 8 月 5 日
Thanks, Torsten!
Torsten
Torsten 2025 年 8 月 5 日
Or:
x = 0:0.1:7;
nnz(x<=3)
ans = 31

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by