How to count no of iterations of first digit.
1 次查看(过去 30 天)
显示 更早的评论
I want to count number of times first digit of first column is repeating. If
a = [11 3;
12 4;
13 3;
21 2;
22 5;
23 6;
24 3];
So, I want to get result in form of 1 = 3 and 2 = 4
2 个评论
the cyclist
2017-1-23
Is that column guaranteed to be two-digit numbers, or could it be
a = [ 11 3;
121 4]
?
采纳的回答
更多回答(1 个)
the cyclist
2017-1-23
a = [11 3;
12 4;
13 3;
21 2;
22 5;
23 6;
243 3];
a1 = a(:,1);
firstDigits = floor(a1./(10.^floor(log10(a1))));
uniqueFirstDigit = unique(firstDigits);
firstDigitCount = histcounts(firstDigits,[uniqueFirstDigit; Inf])'
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gas Dynamics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!