필터 지우기
필터 지우기

Count values in the given array

조회 수: 1 (최근 30일)
Turbulence Analysis
Turbulence Analysis 2023년 10월 21일
댓글: Star Strider 2023년 10월 21일
Hi,
In the attached array, column 1 got two values -3.14 and -3.84 and on column 2 some values are 0 and some are 1. I need to check how many zeros and 1 are in -3.14 and -3.84.

채택된 답변

Star Strider
Star Strider 2023년 10월 21일
편집: Star Strider 2023년 10월 21일
Try this —
LD = load('matlab.mat');
AA4 = LD.AA4
AA4 = 716×2
-3.4100 0 -3.4100 0 -3.4100 0 -3.4100 0 -3.4100 1.0000 -3.4100 0 -3.4100 0 -3.4100 0 -3.4100 1.0000 -3.4100 0
[UAA4,ix1,ix2] = unique(AA4(:,1));
Zeros = accumarray(ix2, (1:numel(ix2))', [], @(x)nnz(AA4(x,2) == 0));
Ones = accumarray(ix2, (1:numel(ix2))', [], @(x)nnz(AA4(x,2) == 1));
NrZeros = table(UAA4, Zeros, Ones)
NrZeros = 2×3 table
UAA4 Zeros Ones _____ _____ ____ -3.84 303 71 -3.41 232 110
See the documentation on unique and accumarray for details.
.
  댓글 수: 2
Turbulence Analysis
Turbulence Analysis 2023년 10월 21일
Thanks, Very much !
Star Strider
Star Strider 2023년 10월 21일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by