필터 지우기
필터 지우기

Counting First digit of a certain number

조회 수: 5 (최근 30일)
Min
Min 2024년 3월 12일
댓글: Min 2024년 3월 13일
Hi, I am working with a large number of data to analyze if there are any failures in data which having some hard time manually looking at the data or even with graphs. So I was wondering if there is a way to count the first digit number out of table which then I just need to look into how many failures happened. Thanks in advance...
For example,
t = [0, 0; 0, 1; 0, 1; 1, 1; 1, 0; 0, 0; 0, 1]
t = 7×2
0 0 0 1 0 1 1 1 1 0 0 0 0 1
t2 = [1, 1; 0, 1; 0, 1; 0, 1; 1, 1; 0, 1; 1, 1]
t2 = 7×2
1 1 0 1 0 1 0 1 1 1 0 1 1 1
t3 = [0, 1, 1; 1, 0, 0; 1, 1, 0; 1, 0, 1; 1, 1, 0; 0, 0, 1; 1, 1, 1]
t3 = 7×3
0 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 0 1 1 1 1
then
T_count = [1, 2]
T_count = 1×2
1 2
T2_count = [3, 1]
T2_count = 1×2
3 1
T3_count = [2, 4, 3]
T3_count = 1×3
2 4 3

채택된 답변

Stephen23
Stephen23 2024년 3월 12일
t1 = [0, 0; 0, 1; 0, 1; 1, 1; 1, 0; 0, 0; 0, 1];
t2 = [1, 1; 0, 1; 0, 1; 0, 1; 1, 1; 0, 1; 1, 1];
t3 = [0, 1, 1; 1, 0, 0; 1, 1, 0; 1, 0, 1; 1, 1, 0; 0, 0, 1; 1, 1, 1];
fh = @(m) sum(diff([0*m(1,:);m],1,1)>0,1);
fh(t1)
ans = 1×2
1 2
fh(t2)
ans = 1×2
3 1
fh(t3)
ans = 1×3
2 4 3
  댓글 수: 7
Min
Min 2024년 3월 13일
Oh! I see, yep my data was in a form of table since I was working with the timetable data.
I will go ahead and make some changes and see if I see any error. Thank you!
Min
Min 2024년 3월 13일
Hi Stephen, I tried out with some changes and it works great.
Thank you :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vehicle Network Toolbox에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by