% This just displays what's happening for one x. In a graph! y = 6171; result(1) = y; count = 1; while y > 1 && count < threshold, % x is the start number. iterate, changing y! if mod(y,2) y = 3*y + 1; end y = y/2; result(count) = y; count = count+1; end x = 1:length(result); plot(x,result,'x-')