I\'ve already have my vector and number of zeros and ones with this code:
u=[1 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0]
transitions=(find(u~=[u(2:end),
If I understand you correctly it is very simple:
p1=sum(u)./numel(u); % is the percentage of ones
p2=1-p1; % is the percentage of zeros
Matlab has even this spesific function called tabulate that creates a frequency table just for that:
tabulate(u)
Value Count Percent
0 13 52.00%
1 12 48.00%
This is just psuedocode so it'll need to be translated, but here's a potential solution:
total = 0;
total_ones = 0;
total_zeroes = 0;
for(i=0; i<transitions.length; i++){
total += transitions[i];
if(value[i] == 0)
total_zeroes += transitions[i];
else
total_ones += transitions[i];
}
print("Percent Zeroes: " + (total_zeroes/total)*100);
print("Percent Ones: " + (total_ones/total)*100);
#To print each group's percent it'd be along the lines of the following:
for(i=0; i<transitions.length; i++){
print("Percent of total comprised of this group: " + (transitions[i]/total)*100)
}