How to select rows that precede and follow a specific row with a certain value?

2 ビュー (過去 30 日間)
Steve Schulz
Steve Schulz 2021 年 11 月 16 日
コメント済み: Steve Schulz 2021 年 11 月 16 日
Hey there,
I'm currently working with experimental data that is stored in a 288 x 25 double (288 = total number of trials ; 25 = variables of interest). Column '13' represents the 'correctness' coded as 1 = correct and 0 = error. What I'm trying to do is to select sequences of '1 0 1' that is every row that precedes an error trial and every row that follows the same error trial. I want to store the 'pre-error-trials' and the 'post-error-trials' as variables separately.
Since I'm still a newbie to Matlab I'm not familiar with every concept but I guess that logcial indexing might play a role here?
I would be very grateful if you could provide some help.

採用された回答

Matt J
Matt J 2021 年 11 月 16 日
c=data(:,13);
preError=data( c(1:end-1)==1 & c(2:end)==0 ,:);
postError=data( c(1:end-1)==0 & c(2:end)==1 ,:);
  7 件のコメント
Matt J
Matt J 2021 年 11 月 16 日
Oh, it seems that you are familiar with this?
No, but clearly if the column data(:,13) begins or ends with a 0, it will happen.
Steve Schulz
Steve Schulz 2021 年 11 月 16 日
Ah, I got it. Thanks !

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by