Counting the number of increments in a vector

7 vues (au cours des 30 derniers jours)
Scott Banks
Scott Banks le 5 Août 2025
Commenté : Torsten le 5 Août 2025
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

Réponse acceptée

Torsten
Torsten le 5 Août 2025
Déplacé(e) : Torsten le 5 Août 2025
x = 0:0.1:7;
numel(x(x<=3))
ans = 31
  2 commentaires
Scott Banks
Scott Banks le 5 Août 2025
Thanks, Torsten!
Torsten
Torsten le 5 Août 2025
Or:
x = 0:0.1:7;
nnz(x<=3)
ans = 31

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by