read the size of cell array with the same element
1 次查看(过去 30 天)
显示 更早的评论
Hi I have a cell array looks like follows. How could I read the size of the cell array has the same element? In this case, I have 6 rows of 01.jpg so the first one is 6. I have 2 rows of 04.jpg so the second one is 2 and so forth. Thanks for your help!
%
01,jpg
01,jpg
01,jpg
01,jpg
01,jpg
01,jpg
04,jpg
04,jpg
05,jpg
05,jpg
...
0 个评论
采纳的回答
Guillaume
2017-5-24
Please use valid matlab syntax in your question, so it's not ambiguous. Assuming that your cell array is of the form:
c = {'01,jpg'
'01,jpg'
'01,jpg'
'01,jpg'
'01,jpg'
'01,jpg'
'04,jpg'
'04,jpg'
'05,jpg'
'05,jpg'}
This would work:
[~, ~, id] = unique(c, 'stable');
sequencelengths = diff(find(diff([-Inf; id; Inf])))
0 个评论
更多回答(2 个)
the cyclist
2017-5-24
Here's one way:
C = {
'01,jpg';
'01,jpg';
'01,jpg';
'01,jpg';
'01,jpg';
'01,jpg';
'04,jpg';
'04,jpg';
'05,jpg';
'05,jpg';
}
[~,~,k] = unique(C);
C_counts = histcounts(k,[unique(k); Inf])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!