MATLABのコードって忘れやすい・・・

プログラムのコマンドなんて忘れやすいもの・・・いっそのことネット上に保存してシェアしましょう!!
It's easy to forget command for MATLAB in programming.... Let's share small help for Matlab code with you on the web!!



2013年12月2日月曜日

Psychotoolboxを使う

最近使い始めた心理実験やfMRI・EEG実験に用いる視聴覚刺激を作成するMATLABのツールボックス、Psychotoolboxについての防備録。

(DLの方法など詳細については、ググってください)

  1. Screen関数について

    [VBLTimestamp StimulusOnsetTime FlipTimestamp Missed Beampos] = Screen('Flip', windowPtr [, when] [, dontclear] [, dontsync] [, multiflip]);

    事前にセットされた描画情報を表示する。
    windowPtr: window番号を入力する。windowPtr = Screen('Open',0,0)などで得られる。"windowPtr" is the id of the onscreen window whose content should be shown at
    flip time.

    when: "when" specifies when to flip: If set to zero (default), it will flip
    on the next possible video retrace. If set to a value when > 0, it will flip at
    the first video retrace after system time 'when' has been reached.

    dontclear: "dontclear" If set to 1, flip will not clear the framebuffer after Flip - this allows
    incremental drawing of stimuli. The default is zero, which will clear the
    framebuffer to background color after each flip. A value of 2 will prevent Flip
    from doing anything to the framebuffer after flip. This leaves the job of
    setting up the buffer to you - the framebuffer is in an undefined state after
    flip.

    dontsync: "dontsync" If set to zero (default), Flip will sync to the vertical
    retrace and will pause execution of your script until the Flip has happened. If
    set to 1, Flip will still synchronize stimulus onset to the vertical retrace,
    but will *not* wait for the flip to happen: Flip returns immediately and all
    returned timestamps are invalid. A value of 2 will cause Flip to show the
    stimulus *immediately* without waiting/syncing to the vertical retrace.

    multiflip: "multiflip" defaults to zero: If set to a value greater than zero, Flip will
    flip *all* onscreen windows instead of just the specified one. This allows to
    synchronize stimulus onset on multiple displays, e.g., for multidisplay stereo
    setups or haploscopes. You need to (somehow) synchronize all attached displays
    for this to operate tear-free. Flip (optionally) returns a high-precision
    estimate of the system time (in seconds) when the actual flip has happened in
    the return argument


    ex) fixation point と barを表示

    %凝視点の線分座標
    FixationXY =...
          [-20, 20,  0,  0;
             0, 0, -20, 20];

    AttentionBarXY =...
          [-390, -390, 390, 390;
           30,  -30,  30, -30];

    Screen('DrawLines', win, FixationXY, 2, [255 0 0], [centerX, centerY]);
    Screen('DrawLines', win, AttentionBarXY, 3, [255 255 255], [centerX, centerY]);
    Screen('Flip', win);


    2011年6月14日火曜日

    重複するペアーを削除 pairfind

    こんな関数作ってみました。
    temp1は2行X列の行列。縦のペアが他の列で重複するものがある場合、
    検索して自動的に削除してくれます。

    function temp=pairfind(temp1)
    % Remove overlapped pair.
    % ---Input---
    % temp1: matrix(2 x X)
    %
    temp=temp1;
    for k=1:size(temp,2)-1,
    idx=[];
    for kk=k+1:size(temp,2),
    if((temp(1,k)==temp(1,kk))&&(temp(2,k)==temp(2,kk))),
    idx=[idx kk];
    %disp('bingo!')
    end
    end
    temp(:,idx)=[];
    end
    %%%%%% END %%%%%%%%%%%%

    (例)
    AA=[1 2 3 1 2 3 1 2 3 1 2 3;
    1 1 1 1 2 2 2 2 3 3 3 3];

    rA=pairfind(AA)

    rA =

    1 2 3 2 3 1 3 1 2
    1 1 1 2 2 2 3 3 3

    2011年5月19日木曜日

    ファイルの移動 filemove

    ファイルを移動させたい時に使う関数。
    ファイル名を変更したいときにも使えます。

    filemove


    ファイル操作に関してまとめてあるのがココ

    2011年5月10日火曜日

    anova

    anovaの1因子解析で、各サンプルの個数が異なるときの評価の仕方がこちら↓

    ANOVA+多重比較解析

    例1の方法を参照すればよい。これは便利だと思う。

    そのほかの検定方法についてはこちら
    Matlabによる初歩の検定

    2010年10月28日木曜日

    wrev ベクトルのフリップ

    ベクトルを反転させるのには、wrevという関数が使える。
    といっても、中身は非常にシンプル。あえて、関数化する必要もないと思うのだが・・・

    y=wrev(x)

    x:ベクトル

    2010年10月13日水曜日

    Voronoi tessellation ボロノイ図

    ボロノイ図は平面的に何かを表現するときに便利。
    このブログと同じようにコードを書いているサイト発見(ここ
    参考までにどうぞ。

    2010年10月6日水曜日

    ANOVA 分散因子解析

    3群比較などの検定を行う時に使うのがANOVA解析。


    p = anova1(X)
    p = anova1(X,group)
    p = anova1(X,group,displayopt)
    [p,table] = anova1(...)
    [p,table,stats] = anova1(...)

    行列Xは(サンプルX群)で入力する。
    p値が十分小さければ、群間の平均は等しくなく、有意差があることになる。
    その後、post hocテストで正式に有意差を示すことができる(ここを参照)。

    multcompare

    という関数にstatsを入力すればOKらしい。


    (例)
    [p t st]=anova1(X,{'50Hz','200Hz','800Hz'},'off');
    [c,m,h,nms]=multcompare(st,'display','on');
    [nms num2cell(m)]