How to find the time of event?

4 ビュー (過去 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
  1 件のコメント
Daria Ivanchenko
Daria Ivanchenko 2020 年 5 月 26 日
Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by