If I have a logical array with 2 or more sets of continuous true values, how do I just grab the first or second continual set, for example?

조회 수: 6 (최근 30일)
Suppose I have the vertical logical array:
[0 0 0 1 1 1 1 0 0 0 1 1 0 0 ]'
What is the simplest way to reference (ie get row numbers) or extract just the first or set of true values (ie., ans = [4,5,6,7]) in the array?

채택된 답변

Jan
Jan 2017년 8월 1일
편집: Jan 2017년 8월 1일
v = [0 0 0 1 1 1 1 0 0 0 1 1 0 0];
ini = strfind(v, [0, 1]);
fin = strfind(v, [1, 0]);
idx = (ini(1) + 1):fin(1)
Or perhaps:
ini = find(v, 1);
fin = strfind(v, [1, 0]);
idx = ini:fin(1)

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by