counting the values and variables
10 views (last 30 days)
Show older comments
I have a dataset 50x62
for example
S=['F' 'D' 'C' 'D' 'C';'C' 'C' 'F' 'D' 'F']
these variables are my output from one operation,now i want to count the number of variables
here i have 2 rows and number of variable is 3
so i need as
F D C
1 2 2
2 1 2
PLEASE HELP
Accepted Answer
Daniel Shub
on 25 Mar 2012
What about a nice loop:
S=['F' 'D' 'C' 'D' 'C';'C' 'C' 'F' 'D' 'F'];
x = sort(unique(S));
fprintf('%c\t', x')
fprintf('\n')
for ii = 1:size(S, 1)
for jj = 1:length(x)
temp(jj) = length(find(S(ii, :) == x(jj)));
end
fprintf('%d\t', temp);
fprintf('\n')
end
11 Comments
More Answers (1)
Wayne King
on 25 Mar 2012
S = ['F' 'D' 'C' 'D' 'C';'C' 'C' 'F' 'D' 'F'];
NumVars = length(unique(S));
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!