필터 지우기
필터 지우기

How to count no of iterations of first digit.

조회 수: 2 (최근 30일)
Vishal Sharma
Vishal Sharma 2017년 1월 23일
답변: the cyclist 2017년 1월 23일
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
the cyclist 2017년 1월 23일
Is that column guaranteed to be two-digit numbers, or could it be
a = [ 11 3;
121 4]
?
Vishal Sharma
Vishal Sharma 2017년 1월 23일
Two digits only

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2017년 1월 23일
편집: Stephen23 2017년 1월 23일
Assuming that there are always two digits:
>> a = [11 3;
12 4;
13 3;
21 2;
22 5;
23 6;
24 3]
>> tmp = fix(a(:,1)/10);
>> uni = unique(tmp);
>> cnt = histc(tmp,uni)
cnt =
3
4
>> [uni,cnt]
ans =
1 3
2 4

추가 답변 (1개)

the cyclist
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])'

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by