MATLAB: Error for exceeding the loop

loop

Hi,
I have d = {[5:10] [20:30]}; e = [1 2 7 8 9 11 12 15 16 22 25 30 35 40 45]; I want to extract values from e which falls into vectors of d.
Result = { [7 8 9] [22 25 30] } because 7, 8 and 9 are within 5 and 10; 22, 25 and 30 are within 20 and 30.
The code I tried gave what I want but when i == 3, the error happened. How can I stop j loop when all vectors in d have been checked. Thank you!
``clc; clear; close alld = {[5:10] [20:30]};e = [1 2 7 8 9 11 12 15 16 22 25 30 35 40 45];E = length(e);D = length(d);for i = 1:D        while j <= max(d{end})        for j = 1:E            if e(j) >= min(d{i})                     a(i) = e(j);                for k = j+1:E                    if e(k) > max(d{i})                    b(i) = e(k-1);                               want{i} = [e(j:k-1)];                                            if ~isempty(b(i))                            j=k;                            i=i+1;                           break;                        end                       end                                  end                         end              end                          endend``

``d = {[5:10] [20:30]};e = [1 2 7 8 9 11 12 15 16 22 25 30 35 40 45];N = length(d) ;result = cell(N,1) ; for i = 1:N  iwant{i} = intersect(e,d{i}) ;end``