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 CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by