create a for loop that makes a new vector between 5 and 75, counts the number of elements %in vector "x” that fall in each range in matlab

main.m
% Creating a vector between 5 and 75 with a step of 5
new_vec = 5:5:75;

% Creating an example vector "x"
x = [12 28 45 60 34 21 9 78 50 16];

% Initializing the counts vector
counts = zeros(1,length(new_vec));

% Looping through the new vector
for ii = 1:length(new_vec)
    
    % Counting the number of elements in "x" that fall in the current range
    counts(ii) = sum(x>=new_vec(ii) & x<new_vec(ii)+5);
    
end

% Displaying the counts vector
counts
457 chars
20 lines

Output:

main.m
counts =

     2     0     1     1     1     1     0     1     0     2
71 chars
4 lines

gistlibby LogSnag