MATLABでデータファイルを作成するための適切なコード/書式を理解することが非常に困難です。何らかの理由で、この特定のタスクは本当に私を混乱させるだけです。MATLABデータファイルの書式設定
function semjudge
SubNum = ('Subject Number: ','s');
files = dir(fullfile('pictures','*.png'));
nFiles = numel(files);
combos = nchoosek(1:nFiles, 2);
index = combos(randperm(size(combos, 1)), :);
picture1 = files(index(1)).name;
picture2 = files(index(2)).name;
image1 = fullfile('pictures',picture1);
image2 = fullfile('pictures',picture2);
subplot(1,2,1); imshow(image1); title(picture1);
subplot(1,2,2); imshow(image2); title(picture2);
uicontrol('Style', 'text',...
'Position', [200 45 200 20],...
'String','How related are these pictures?');
uicontrol('Style', 'text',...
'Position', [50 45 100 20],...
'String','Unrelated');
uicontrol('Style', 'text',...
'Position', [450 45 100 20],...
'String','Closely related');
uicontrol('Style','pushbutton','String','Next Trial',...
'Position', [250 350 100 20],...
'Callback','clf; semjudge()');
h = uicontrol(gcf,...
'Style','slider',...
'Min' ,0,'Max',50, ...
'Position',[100 20 400 20], ...
'Value', 25,...
'SliderStep',[0.02 0.1], ...
'BackgroundColor',[0.8,0.8,0.8]);
set(gcf, 'WindowButtonMotionFcn', @cb);
lastVal = get(h, 'Value');
function cb(s,e)
if get(h, 'Value') ~= lastVal
lastVal = get(h, 'Value');
fprintf('Slider value: %f\n', lastVal);
end
end
end
非常にシンプル少しスクリプト:
は、だから私はこのスクリプトを持っています。これは、フォルダから2つのランダムな画像を引っ張り、ユーザはそれらを比較するように求められます。私が欲しいのは、件名の数により標識データファイル、のようなものです:
fid = fopen(strcat('data','_',SubNum,'.txt'),'a');
、データファイル自体、私はスライダーでそれに割り当てられた各画像のタイトル、および値を含むようにしたいです。ユーザーが '次の試用'ボタンを押すと、タイトル(picture1)とタイトル(picture2)とlastValが保存されます。
これは非常に基本的な質問ですが、私が非常に混乱しているとわかっているデータファイルに関するMathWorksのドキュメントは、私はそれを行う方法を理解していません。
なぜSliderコールバック関数の代わりに 'WindowButtonMotionFcn'イベントを使用しますか?ここのように:http://www.mathworks.com/help/techdoc/creating_guis/f10-998412.html#f10-1001483 – yuk
Nevermind、エラーは修正されました。それはコードのいくつかの行では単にタイプミスでした。ありがとう! –