Stats

Popular Posts

Followers

Mathematica 教學 資料依指定區間分組

戴忠淵 於 2013年12月10日星期二 下午6:16 發表

 作者  celestialgod (攸藍)                                       看板  MATLAB  標題  [運算] 給定區間分組  時間  Tue Dec 10 15:59:41 2013 ───────────────────────────────────────  data = randn(3670000,1);  我有一個區間是  -3 -2 -1 0 1 2 3  我想要把資料中小於-3分為第一組,界在-3跟-2之間分為第二組,剩下依此類推


data=RandomReal[{-5,7},100];
group=Partition[{-5,-4,-1,2,4,6,7},2,1];
myInterval[mynum_]:=Position[IntervalMemberQ[Interval[#],mynum]&/@group,True][[1,1]];
Gather[Sort@data,myInterval[#1]==myInterval[#2]&]
GatherBy[Sort@data,myInterval[#]&]

Tags: , ,

讀者回應 ( 0 意見 )

發佈留言

Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.

如果這篇文章對你有幫助,那請留個訊息給我~