(*產生100組,每組200個數字的隨機資料*) temp=Sort[#]&/@RandomReal[{0,50Pi},{100,200}]; data=Map[{#,Sin[#]}&,temp,{2}] (*畫出所有資料的序列圖*) Graphics[Line[#]&/@Partition[#,2,1],Epilog->{Red,Point[#]}, Frame->True,ImageSize->1000]&/@data (*第一組資料的圖形*) Graphics[Line[#]&/@Partition[data[[1]],2,1], Epilog->{Red,Point[data[[1]]]},Frame->True,ImageSize->1000] (*先分析第一組,找出所有的相對低點。若該組資料的y值較上一組資料的y值小,*) (*就歸為同一組。所以若長度為一則表示資料在遞增,故剔除。*) low=Select[Split[data[[1]],#1[[2]]>#2[[2]]&],Length[#]>1&][[All,-1]] (*同樣的方法可應用在相對高點*) high=Select[Split[data[[1]],#1[[2]]<=#2[[2]]&],Length[#]>1&][[All,-1]] (*輸出所有資料的相對高低點*) datalow=Select[Split[data[[#]],#1[[2]]>#2[[2]]&], Length[#]>1&][[All,-1]]&/@Range[Length@data] datahigh=Select[Split[data[[#]],#1[[2]]<=#2[[2]]&], Length[#]>1&][[All,-1]]&/@Range[Length@data]
Mathematica 教學 找出資料序列的所有相對高低點
由 戴忠淵 於 2012年11月6日星期二
上午6:40 發表
讀者回應 ( 0 意見 )
訂閱發佈留言 (Atom)
發佈留言
Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.
如果這篇文章對你有幫助,那請留個訊息給我~