categorical histograms: combining missing category values

hello,
let say i have categorical data1 which is in histogram form values, counts and a 2nd histogram with its own counts, values. each has similar bins but each are missing values from each other.
how do i fill in each other missing category values?
example
data 1 categories {'a' 'b' 'm' 'u' 'z'} counts[10 4 12 23)
data 2 categories {'a' 'aa' 'b' 'e'} counts(2 1 5 7)
final result
data 1 categories {'a' 'aa' 'b' 'e' 'm' 'z'} counts(10 0 4 0 12 23)
data 2 categories {'a' 'aa' 'b' 'e' 'm' 'z'} counts(2 1 5 7 0 0)
thanks for any help.

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 30 Juil 2014
Modifié(e) : Azzi Abdelmalek le 30 Juil 2014
a1={'a' 'b' 'm' 'z'};
b1=[10 4 12 23];
a2={'a' 'aa' 'b' 'e'};
b2=[2 1 5 7];
c=unique([a1 a2]);
data1=zeros(1,numel(c));
data2=data1;
data1(ismember(c1,a1))=b1
data2(ismember(c1,a2))=b2

4 commentaires

G commented
Hello Azzi,
Many thanks for quick reply.
I get an error on this data, I think because there are missing values and lengths are not the same.
ValuF=
'0'
'001f3601'
'010f6491'
'1575c75f'
'24657b11'
'2bf691b1'
'33d94071'
'3a6f6b59'
'3d2bedd7'
'445bbe3b'
'46fbac64'
'47907db5'
'51c3d1d4'
'5c813496'
'60c2b362'
'724b04da'
'7a402766'
'82d3ae39'
'875ea8a7'
'8b8de563'
'8f8c5acd'
'9721386e'
'9b3e8820'
'9d93af03'
'b9266ff0'
'c0812fc5'
'c243e98b'
'c9f3bea7'
'cb079c2d'
'ce62e669'
'e13f3bf1'
'e8b83407'
'ea9a246c'
'f0f449dd'
'f55c04b6'
'f5b6afe5'
'fd2fe0bd'
ValuP=
'0'
'001f3601'
'010f6491'
'07ee399f'
'1575c75f'
'2bf691b1'
'33d94071'
'3a6f6b59'
'3d2bedd7'
'445bbe3b'
'46fbac64'
'47907db5'
'51c3d1d4'
'5c813496'
'60c2b362'
'724b04da'
'7a402766'
'8f8c5acd'
'9721386e'
'9b3e8820'
'9d93af03'
'b9266ff0'
'c0812fc5'
'c243e98b'
'c9f3bea7'
'cb079c2d'
'ce62e669'
'e13f3bf1'
'e8b83407'
'ea9a246c'
'f0f449dd'
'f55c04b6'
'fd2fe0bd'
Error using strcmpi Inputs must be the same size or either one can be a scalar. Error in cell/unique (line 102)
foundflag = strcmpi(flag,flagvals);
I can union to get the composite categories but then how to carry the counts over and add 0?
G to add a comment click on comment on this answer Do not add answers
What your comment has to do with your original question?
g
g le 30 Juil 2014
obviously there seemed to be an error
'c1' should be 'c'
i fixed it and it works.
thanks for the help.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by