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

7 visualizaciones (últimos 30 días)
shin
shin el 19 de Nov. de 2020
Comentada: shin el 21 de Nov. de 2020
 以下のような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に変換できません とエラーが出てきてしまい、うまくいきません。

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!