ソフトウェア/Igor のバックアップソース(No.3)
更新[[公開メモ]] #contents * Igor とは [#k3f1dcd4] データ解析に Wave Metrics 社の Igor Pro を使っています。 なかなか癖のあるソフトですが、 Igor 上でプログラムを組むことでかなり複雑なデータ解析も自動化できていろいろ捗ります。 ここには使い回しの効きそうなコード例を上げていこうと思います。 公式のオンラインヘルプはこちら: http://www.hulinks.co.jp/support/igor/programming/index.html * 分野別記事へのリンク [#cb75dc8d] #ls2("ソフトウェア/Igor") * あるグラフ上に表示されたウェーブの一覧を表示する [#n02b667a] LANG:Igor string graph_name = "Graph1" string traces = TraceNameList(graph_name, ";", 1) variable i for(i = ItemsInList(traces) - 2; i>=0; i-=1) print StringFromList(i, traces) endfor 画像の一覧なら、TraceNameList ではなく ImageNameList を呼べばいい。 LANG:Igor string graph_name = "Graph1" string images = ImageNameList(graph_name, ";", 1) variable i for(i = ItemsInList(images) - 2; i>=0; i-=1) print StringFromList(i, images) endfor * グラフウィンドウ上の選択領域を得る [#d6fd38cf] グラフ上をマウスで斜めにドラッグすると矩形領域を選べますが、 この範囲を Igor では Marquee と呼んでいます。 使用例 LANG:Igor // 与えられた座標がグラフの選択領域に含まれているかどうか返す function IsPointInSelectedRegion(x, y) variable x, y string graph_name = "Graph1" struct Rectangle selected_region GetMarqueeRegion(graph_name, selected_region) return IsPointInRect(x, y, selected_region) end コード LANG:Igor // 矩形領域を格納するための構造体 Structure Rectangle double left double right double top double bottom EndStructure // 指定された名前のグラフから選択範囲を得る // 選択されていなければ全範囲 (left, bottom 軸で) を返す function GetMarqueeRegion(graph_name, region) string graph_name Struct Rectangle ®ion GetMarquee/W=$graph_name left, bottom if(!V_Flag) GetAxis/q/W=$graph_name bottom V_Left = V_min V_Right = V_max GetAxis/q/W=$graph_name left V_Top = V_min V_Bottom = V_max endif region.left = V_Left region.right = V_Right region.top = V_Top region.bottom = V_Bottom end // x, y で指定された点が rect 領域に入っているかどうかを返す function IsPointInRect(x, y, rect) variable x, y Struct Rectangle &rect variable result result = rect.left <= x result = x <= rect.right && result result = rect.top <= y && result result = y <= rect.bottom && result return result end * グラフ上の選択範囲を設定する [#dcd89a94] SetMarquee を使えばいいのですが、単位をポイントに直さなければならないので、 PixelFromAxisVal と ScreenResolution を呼んで変換します。 コード LANG:Igor // 下軸、左軸の値を指定してグラフの選択範囲を設定する function image_mouseup(x1, y1, x2, y2) variable x1, y1, x2, y2 x1 = PixelFromAxisVal("image", "bottom", x1) / ScreenResolution * 72 x2 = PixelFromAxisVal("image", "bottom", x2) / ScreenResolution * 72 y1 = PixelFromAxisVal("image", "left", y1) / ScreenResolution * 72 y2 = PixelFromAxisVal("image", "left", y2) / ScreenResolution * 72 SetMarquee/w=image, x1, y1, x2, y2 end
Counter: 14303 (from 2010/06/03),
today: 2,
yesterday: 0