count number of variance in CSV files

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 25 Lug 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 Commenti
mohammad Alsajri
mohammad Alsajri il 26 Lug 2019
thanks alot, now its working
Star Strider
Star Strider il 26 Lug 2019
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by