how to cluster bit strings using matlab
1 次查看(过去 30 天)
显示 更早的评论
A= [ 1 0 0 0 0 0 1 1 0,
0 0 0 0 1 1 0 0 1,
1 1 1 1 1 1 1 0 0,
1 1 1 1 1 1 1 0 0,
1 0 0 0 0 0 1 1 0,
0 0 0 0 1 1 0 0 1,
1 1 1 1 1 1 1 1 1]
let A be the binary matrix.. 1 means there is decrease in production and 0 means there is increase in production ..
how will i cluster the same bit strings patterns?
i m working on health care data set[rows= 453 and col = 60] .. 1 represent decrease and 0 represent increase ..can this be possible using loops..
note: order of bits are important..// order dependent
8 个评论
Walter Roberson
2016-5-6
The original code used
A= [ 1 0 0 0 0 0 1 1 0,
0 0 0 0 1 1 0 0 1,
1 1 1 1 1 1 1 0 0,
and so on. MATLAB does know to treat the end of line line a semi-colon in that case.
采纳的回答
Guillaume
2016-5-6
It sounds like you just want to identify all identical 'bit strings' and assign them the same ID. This can easily be achieved with unique.
First, let's change A into something useful, since as mentioned in the comment to your question A is not "7 bit strings separated by commas", matlab ignores the commas. While we're at it, let's give the variable a name that has meaning:
A = [ 1 0 0 0 0 0 1 1 0, 0 0 0 0 1 1 0 0 1, 1 1 1 1 1 1 1 0 0, 1 1 1 1 1 1 1 0 0, 1 0 0 0 0 0 1 1 0, 0 0 0 0 1 1 0 0 1, 1 1 1 1 1 1 1 1 1]
bitstreams = reshape(A, 9, [])'; %reshape A into an n x 9 array
To give a unique ID to each identical bit stream we can simply use the third return value of unique, with the 'rows' option to the unique to consider each row as a complete object.
[~, ~, id] = unique(bitstreams, 'rows', 'stable') %stable optional
This returns
id = [1; 2; 3; 3; 1; 2; 4]
where you can see that the 1st and 5th bitstream have been assigned id 1, the 2nd and 6th id 2, the 3rd and 4th id 3, and the last one id 4.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!