特定の複数列から条件を指定し、複数の行を抽出する

조회 수: 8 (최근 30일)
shin
shin 2020년 11월 19일
댓글: shin 2020년 11월 21일
 以下のようなdatファイルをreadtableで読み込んだ際に、eventIDとnameが条件に一致する場合を取り出したいのですがうまくいきません
eventID energy x y z name
____ _______ _____ ______ _________ _________________
0 0.2007 477.8 0 -0.001755 {'Compton' }
0 0.07819 479.4 2.96 2.991 {'Compton' }
0 0.06179 482 2.418 4.056 {'Compton' }
0 0.1703 485.5 10.41 4.328 {'PhotoElectric'}
1 0.3191 407.7 0 -0.001498 {'Compton' }
1 0.03521 404 -3.865 1.617 {'Compton' }
1 0.0325 403.6 -3.799 3.284 {'Compton' }
2 0.1383 427.3 0 -0.001569 {'Compton' }
2 0.01936 471.1 -53.27 9.833 {'Compton' }
3 0.04832 463.8 0 -0.001704 {'Compton' }
10000 ・・・・・・・・
条件は、
eventID ・・・・ name
_______ _____________
15 {'Compton' }
15 {'PhotoElectric'}
  eventID ・・・・ name
_______ _____________
27 {'Compton' }
27 {'Compton' }
   27      {'PhotoElectric'}
のようなときの複数行を取り出したいです。これをeventIDが10000のところまで繰り返して行いたいです。
findで試してみたりしているのですが、tableからlogicalに変換できません とエラーが出てきてしまい、うまくいきません。

채택된 답변

Takao
Takao 2020년 11월 20일
こんな感じでうまくいきませんかね。
data = readtable(XXXX)
i = 0:10000
rows = (data.eventID == i);
target(i) = data(rows);
end
find関数を使うよりも条件式を使ったほうがすっきりする気がします。
  댓글 수: 1
shin
shin 2020년 11월 21일
やはり条件文で回した方がいいですよね・・・ありがとうございます!

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

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!