1
我很難理解用於在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
很簡單的小腳本。它從文件夾中拉出兩張隨機圖片,並要求用戶比較它們。我想要的是由主體編號標記的數據文件,是這樣的:
fid = fopen(strcat('data','_',SubNum,'.txt'),'a');
數據文件本身我想包含由滑塊分配給它的每個圖像的名稱和值。因此,當用戶按下「下一個試用」按鈕時,它會保存標題(picture1)和標題(picture2)以及lastVal。
我意識到這是一個非常基本的問題,但我發現數據文件的MathWorks文檔非常混亂,我不明白該怎麼做。
爲什麼使用'WindowButtonMotionFcn'事件而不是Slider回調函數?像這裏:http://www.mathworks.com/help/techdoc/creating_guis/f10-998412.html#f10-1001483 – yuk 2012-02-20 23:49:58
沒關係,錯誤是固定的;這只是在代碼的某一行輸入錯誤。謝謝! – 2012-02-21 15:13:49