필터 지우기
필터 지우기

how to count the number of consecutive values

조회 수: 5 (최근 30일)
pamela sulis
pamela sulis 2016년 3월 29일
댓글: pamela sulis 2016년 3월 30일
Hi! I have Location(1,4).loc that is a 137x19 cell array. I want to find the number of time that first column have value '674' and the consecutive value in the second column is '673'. How can I do?

채택된 답변

Matthew Eicholtz
Matthew Eicholtz 2016년 3월 29일
편집: Matthew Eicholtz 2016년 3월 29일
Use strcmp, which works well for cell arrays of strings. Compare the first column to the string '674' and the second column to '673'.
x = Location(1,4).loc;
sum(strcmp(x(:,1),'674') & strcmp(x(:,2),'673'))
When I ran the above code on the data you provided, I got a result of 13.
  댓글 수: 3
Matthew Eicholtz
Matthew Eicholtz 2016년 3월 29일
I assume you mean something like this?
y = {'1' '256'; '674' '631'; '674' '673'}; %target values
for ii=1:size(y,1)
cnt(ii) = sum(strcmp(x(:,1),y{ii,1}) & strcmp(x(:,2),y{ii,2}));
end
pamela sulis
pamela sulis 2016년 3월 30일
thanks! :)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by