How to find the time of event?

조회 수: 3 (최근 30일)
Daria Ivanchenko
Daria Ivanchenko 2020년 5월 26일
댓글: Daria Ivanchenko 2020년 5월 26일
Hi! I have a matrix with two columns. The first column is time and the second one is events consisted of 0 and 1 only. I would like to know the time when the event (1) happend. How can I do this?
As an example, the matrix is:
0 0
2.53164556962025 0
5.06329113924051 0
7.59493670886076 0
10.1265822784810 0
12.6582278481013 0
15.1898734177215 0
17.7215189873418 0
20.2531645569620 0
22.7848101265823 1
25.3164556962025 1
27.8481012658228 1
30.3797468354430 1
32.9113924050633 1
35.4430379746836 0
In the end I want to get an answer about what time the first 1 appeared. So for this example it should be:
ans = 22.7848101265823
Thanks for any help!

채택된 답변

Tommy
Tommy 2020년 5월 26일
For this sample matrix:
>> matrix = [cumsum(10*rand(25,1)), rand(25,1) < 0.1]
matrix =
2.6774 0
3.9889 0
10.7113 0
13.0342 0
13.4335 0
13.8455 0
23.4376 0
27.3937 0
33.0231 0
33.0414 0
33.1545 0
35.4013 0
45.2526 0
48.8322 0
49.7725 0
56.3409 1.0000
64.5214 0
66.0233 0
74.9418 0
80.0405 0
87.4213 0
92.1971 0
96.8440 1.0000
106.2857 0
107.8732 0
The following works:
>> t0 = matrix(find(matrix(:,2),1),1)
t0 =
56.3409

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by