function [regions, num_regions] = zrange_1d(xlow, xhigh) regions = cell(0, 1); num_regions = 0; if length(xlow) ~= length(xhigh) disp('Numbers of bits not consistent!'); return; end xl = bin2dec(xlow); xh = bin2dec(xhigh); if xl > xh return; end n = length(xlow); index = find(xlow == '1', 1, 'last'); if length(index) == 1 for i = index:n if xl + 2^(n - i) - 1 <= xh num_regions = num_regions + 1; tmp_region = xlow; for j = (i + 1):n tmp_region(j) = '*'; end regions{num_regions} = tmp_region; if xl + 2^(n - i) > xh break; end next_xlow = dec2bin(xl + 2^(n - i), n); next_xhigh = xhigh; [next_regions, next_num_regions] = zrange_1d(next_xlow, next_xhigh); for j = 1:next_num_regions num_regions = num_regions + 1; regions{num_regions} = next_regions{j}; end break; end end else for i = 1:n if 2^(n + 1 - i) - 1 <= xh num_regions = num_regions + 1; tmp_region = xlow; for j = 1:(n + 1 - i) tmp_region(n + 1 - j) = '*'; end regions{num_regions} = tmp_region; if xl + 2^(n + 1 - i) > xh break; end next_xlow = dec2bin(xl + 2^(n + 1 - i), n); next_xhigh = xhigh; [next_regions, next_num_regions] = zrange_1d(next_xlow, next_xhigh); for j = 1:next_num_regions num_regions = num_regions + 1; regions{num_regions} = next_regions{j}; end break; end end end