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');
데이터 파일 자체에 나는 슬라이더에 할당 된 각 사진의 제목 및 값을 포함합니다. 따라서 사용자가 'Next Trial'버튼을 누르면 lastVal뿐만 아니라 title (picture1)과 title (picture2)도 저장됩니다.
이것이 아주 기본적인 질문이지만, 데이터 파일에 대한 MathWorks 설명서는 매우 혼란스럽고, 어떻게해야하는지 이해할 수 없습니다.
왜 Slider 콜백 함수 대신에'WindowButtonMotionFcn' 이벤트를 사용합니까? 여기처럼 : http://www.mathworks.com/help/techdoc/creating_guis/f10-998412.html#f10-1001483 – yuk
Nevermind, 오류가 수정되었습니다. 그것은 코드의 일부 라인에서 오타였습니다. 감사! –