I have about 100,000 numbers that I would like to group together based on dividing by two or increments of two.
PS: The increment values may change and the values found in the main array "x" can only be used once.
I'm not sure how to check and stop the loop if a number in the "array_all" array has been repeated from the "x" array.
See example below
Example:
x=[9,8,7,6,5,4,3,2,1]
I'm trying to get the array_all array to look like this:
array_all=
[ 9.00000 4.50000 2.25000
8.00000 4.00000 2.00000
7.00000 3.50000 1.75000
6.00000 3.00000 1.50000
5.00000 2.50000 1.25000
1.00000 0.50000 0.25000]
and the dynamically named arrays to look like this
array_dyn_name1=[9,4.5,2.25]
array_dyn_name2=[8,4,2]
array_dyn_name3=[7,3.5,1.75]
array_dyn_name4=[6,3,1.5]
array_dyn_name5=[5,2.5,1.25]
array_dyn_name6=[1,.5,.25]
PS: The reason I don't just stop at the array "array_dyn_name6" is due to that the numbers will not be that simple there will be thousands. And I won't know when they will repeat.
Sequence of events:
1. Start from the highest number in the x array and divide that number and it's output number by two and place that into another array called array_all, do this 3 times
2. Place each row of array_all into a dynamically named array called array_dyn_name
3. Do this for each value in the x array unless the number has already been used before in the array_all array
Note: As you can see the array_all array don't start with 4,3, or 2 because they were previously used in the array_all array
The code below works but I'm not sure how to check and stop the loop if a number in the "array_all" array has been repeated from the "x" array.
%test grouping
clear all, clc, tic, clf;
x=[9,8,7,6,5,4,3,2,1]
div=[1,2,4] %numbers to use as divisor
array_all=[];
for ii=1:length(x)
for jj=1:length(div)
array_all(ii,jj)=x(ii)/div(jj) %divide each number and successive number by div
end
genvarname('array_dyn_name', num2str(ii)) %create dynamic variable
eval(['array_dyn_name' num2str(ii) '= array_all(ii,:)']) %places row into dynamic variable
end
fprintf('\nfinally Done-elapsed time -%4.4fsec- or -%4.4fmins- or -%4.4fhours-\n',toc,toc/60,toc/3600);
My output is below:
array_all =
9.00000 4.50000 2.25000
8.00000 4.00000 2.00000
7.00000 3.50000 1.75000
6.00000 3.00000 1.50000
5.00000 2.50000 1.25000
4.00000 2.00000 1.00000
3.00000 1.50000 0.75000
2.00000 1.00000 0.50000
1.00000 0.50000 0.25000
PS: I'm using octave 3.8.1 it's like matlab