count number of variance in CSV files
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
mohammad Alsajri
le 25 Juil 2019
Commenté : Star Strider
le 26 Juil 2019
hello dear mathworkrs,
I have a CSV file consisting of 41 columnes, all the values are numeric, how can i cont numbers of variance in each column? let us say column 1 consist of 1, 100, 240,0,300,etc I need to calculat or count howmany times 1 is repeated in column1 , howmany times 100 is repeated and soo on, I attached sample of my data.
thanks for help
0 commentaires
Réponse acceptée
Star Strider
le 25 Juil 2019
Some of your columns have all the same values, so for those, just take whatever number is in the first row as the value and the row size is the the number of occurrences. You can find those columns with:
ConstCols = find(ChkCols == 0);
returning the column numbers in ‘ConstCols’.
For the others, this works:
D = xlsread('kdd.xlsx');
ChkCols = sum(diff(D)); % Check For Columns Having All The Same Value
ValidCols = find(ChkCols ~= 0); % Columns With Different Values
for k = 1:numel(ValidCols)
[Ucol,~,ix] = unique(D(:,ValidCols(k))); % Unique Values For This Column
knts = accumarray(ix,1); % Counts For This Column
Out{k,1} = ValidCols(k); % Column Number
Out{k,2} = [Ucol, knts]; % Values & Counts
end
producing for example:
Result_9 = Out{9,1}
Result_9 = Out{9,2}
Result_9 =
37
Result_9 =
0 175
0.01 93
0.02 64
0.03 157
0.04 244
0.05 259
0.06 36
0.07 5
So ‘Out{9}’ is column #37, and it has 175 repeats of 0, 93 repeats of 0.01, and so for the rest.
6 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
