counting the values and variables

10 ビュー (過去 30 日間)
kash
kash 2012 年 3 月 25 日
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
  1 件のコメント
kash
kash 2012 年 3 月 25 日
wayne length gives value as 3,but i need as above

サインインしてコメントする。

採用された回答

Daniel Shub
Daniel Shub 2012 年 3 月 25 日
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 件のコメント
kash
kash 2012 年 3 月 25 日
temp(ii) is 1,temp(jj)is 2
ii loop calculates the row of origal value(S),and jj calculates the column unique variables
kash
kash 2012 年 3 月 25 日
i tried not getting for final time an u code for me for saving output in a variable

サインインしてコメントする。

その他の回答 (1 件)

Wayne King
Wayne King 2012 年 3 月 25 日
S = ['F' 'D' 'C' 'D' 'C';'C' 'C' 'F' 'D' 'F'];
NumVars = length(unique(S));
  1 件のコメント
kash
kash 2012 年 3 月 25 日
thanks wayne another
if i have
A=[1 2 3 2 1 ;2 3 1 1 1];
here i want to count the number of 1's,2s,3's for each row so i get
and store i different variables
A B C
2 2 1
3 1 1

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by