MATLAB Answers

How to write a range of numbers in MATLAB?

354 views (last 30 days)
Abdul Rahim Mahayadin
Abdul Rahim Mahayadin on 9 Apr 2018
Answered: njj1 on 18 Apr 2018
Hi, I am trying to generate a speed range in MATLAB. Let V is the speed, then how to write the coding to find the speed range of:
0<V<=12
12<V<=20
20<V<=30
30<V<=40
40<V<=50
50<V<=60
60<V<=70
70<V<=80
80<V<=90
90<V<=100
100<V<=110
V>110

  2 Comments

Walter Roberson
Walter Roberson on 18 Apr 2018
Please do not close Questions that have been Answered.

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 9 Apr 2018
or you can use the second output of histc() or the third output of histcounts()

  0 Comments

Sign in to comment.


KSSV
KSSV on 9 Apr 2018
V = 1:100 ;
idx = V>=10 & V<=20 ; % Get indices of velocities lying between 10 to 20
V(idx)

  0 Comments

Sign in to comment.


njj1
njj1 on 18 Apr 2018
ranges = [0,12,20:10:110]; %end points of requested speeds
for i = 1:numel(ranges)-1
   v{i} = V((V>ranges(i) & (V<=ranges(i+1))); %speeds between endpoints
   numV{i} = numel(v{i}); %number of speed entries between endpoints
end
v{end+1} = V(V>110);

  0 Comments

Sign in to comment.

Sign in to answer this question.