スライド その2 (slide02)

GUIDEのガイド その2
生体イメージング研究室
北村達也
[email protected]
Dec 19, 2004
1
プロットのプログラム
• 仕様
– テキストファイルからデータを読み込みプロット
– データの読み込みはGUIで
– プロットのラインの色を指定できるようにする
1
2
3
4
5
2
4
6
8
10
データファイルの例
2
メニューエディタ
クリックするとメニュー
が作成される
3
メニューを作成
File
• ラベル File
• タグ MenuFile
Load data
• ラベル Load data
• タグ MenuFileLoadData
ラベルおよびタグの名称はあくまで一例
4
プロット用のエリアを作成
5
ラインの色を選ぶポップアップ
メニューを作成
String
blue
green
red
…
リストボックスでもよい
6
メニューからファイルをロード
• uigetfile
function MenuFileLoad_Callback(hObject, eventdata, handles)
% hObject
handle to MenuFileLoad (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
[file, path] = uigetfile('*.txt', 'Select a text-file');
handles.data = load(fullfile(path, file));
guidata(hObject, handles);
ダイアログウィンドウのタイトル
[file, path] = uigetfile('*.txt', 'Select a text-file');
拡張子を指定
*.*ならすべての拡張子
7
プロット部の追加
• 座標軸を指定してプロット
function MenuFileLoad_Callback(hObject, eventdata, handles)
% hObject
handle to MenuFileLoad (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
[file, path] = uigetfile('*.txt', 'Select a text-file');
handles.data = load(fullfile(path, file));
guidata(hObject, handles);
axes(handles.axes1);
color = get_lineColor(handles);
plot(handles.data(1,:), handles.data(2,:), color);
8
ポップアップメニューの
callback
• 指定した色での再描画
% --- Executes on selection change in PopupLineColor.
function PopupLineColor_Callback(hObject, eventdata, handles)
% hObject
handle to PopupLineColor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
axes(handles.axes1);
color = get_lineColor(handles);
plot(handles.data(1,:), handles.data(2,:), color);
9
get_lineColor
function color = get_lineColor(handles)
contents = get(handles.PopupLineColor, 'String');
selectedString = contents{get(handles.PopupLineColor, 'Value')};
switch (selectedString)
case 'blue'
color = 'b';
case 'green'
color = 'g';
case 'red'
color = 'r';
case 'cyan'
color = 'c';
case 'magenta'
color = 'm';
case 'yellow'
color = 'y';
case 'black'
color = 'k';
end
10
拡張
• グリッドラインのオンオフ
– チェックボックス
– 2つのボタン(アクティブなボタンの制御)
• ラインの太さの指定
– plot(x,y,’b’,’linewidth’,2);
– ポップアップメニュー、リストボックス、エ
ディットテキストなど好みで
• マーカーの指定
– plot(x,y,’bx-’,’linewidth’,2,’markersize’,12);
11