Я сейчас пишу графический интерфейс MATLAB, который даст тест с несколькими вариантами ответов.Он предназначен для работы следующим образом:
Чтобы отслеживать вопросы, на которые даны неправильные или правильные ответы, я использую массив из 1 и 0 (1 является правильным, 0 является неправильным).Каждая позиция индекса в массиве представляет соответствующий вопрос (массив называется rightWrong, rightWrong (1) = оценка за Q1 и т. Д.).Моя проблема заключается в том, что независимо от того, установлю ли я следующую позицию в массиве rightWrong на 1 или 0, все предыдущие значения будут установлены на 0.
GUI состоит из статического текстового поля вверхугруппа кнопок с четырьмя переключателями в центре, двумя кнопками внизу и двумя флажками слева.Во время вскрытия я установил submitButton (кнопка, которая отправляет ответ пользователя на вопрос) и группу кнопок как невидимые.После того, как startButton (кнопка, которая запускает экзамен и вызывает первый вопрос) нажата, она устанавливается как невидимая вместе с флажками, делая submitButton и группу кнопок видимыми.Этот формат используется для остальной части программы, чтобы задавать каждый вопрос и получать вводимые пользователем данные.
Вот код соответствующего раздела.Строка разделяет две подфункции.
% --- Executes on button press in submitButton.
function submitButton_Callback(hObject, eventdata, handles)
% hObject handle to submitButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global counter questions answers name date qNum
% This is the section that I believe the problem occurs in. The rightWrong array
% is the one with the problem. Buttons A through D are the radio buttons
% situated next to their corresponding answer choices
if qNum == 1
rightWrong = ones(1, length(answers));
end
if (get(handles.buttonA,'Value') == 1) && (answers(qNum) == 'a')
rightWrong(1,qNum) = 1
elseif (get(handles.buttonB,'Value') == 1) && (answers(qNum) == 'b')
rightWrong(1,qNum) = 1
elseif (get(handles.buttonC,'Value') == 1) && (answers(qNum) == 'c')
rightWrong(1,qNum) = 1
elseif (get(handles.buttonD,'Value') == 1) && (answers(qNum) == 'd')
rightWrong(1,qNum) = 1
else
rightWrong(1,qNum) = 0
end
counter = counter + 1;
if counter < length(questions)
set(handles.textBox,'String',questions{counter});
counter = counter + 1;
set(handles.buttonA,'String',questions{counter});
counter = counter + 1;
set(handles.buttonB,'String',questions{counter});
counter = counter + 1;
set(handles.buttonC,'String',questions{counter});
counter = counter + 1;
set(handles.buttonD,'String',questions{counter});
qNum = qNum + 1
else % This "else" statement can be ignored: the problem occurs before it is
% triggered.
if (length(name)~=0) && (length(date)~=0)
newGUI(rightWrong, name, date)
elseif (length(name)~=0) && (length(date)==0)
newGUI(rightWrong, name)
elseif (length(name)==0) && (length(date)~=0)
newGUI(rightWrong, date)
elseif (length(name)==0) && (length(date)==0)
newGUI(rightWrong)
end
end
_______________________________________________________________________________________
% --- Executes on button press in startButton.
function startButton_Callback(hObject, eventdata, handles)
% hObject handle to startButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global questions counter qNum
counter = 1;
%Make Invisible
set(handles.startButton,'Visible','off');
set(handles.checkID,'Visible','off');
set(handles.editID,'Visible','off');
set(handles.checkDate,'Visible','off');
set(handles.editDate,'Visible','off');
%Make Visible
set(handles.choiceGroup,'Visible','on');
set(handles.submitButton,'Visible','on');
set(handles.text1,'Visible','on');
set(handles.text2,'Visible','on');
set(handles.text3,'Visible','on');
set(handles.text4,'Visible','on');
% This sections lists the First Question as well as
% all of the possible answers by their respective radio buttons.
set(handles.textBox,'String',questions{counter});
counter = counter + 1;
set(handles.buttonA,'String',questions{counter});
counter = counter + 1;
set(handles.buttonB,'String',questions{counter});
counter = counter + 1;
set(handles.buttonC,'String',questions{counter});
counter = counter + 1;
set(handles.buttonD,'String',questions{counter});
qNum = 1;
Извините, что так много, мне пришлось много менять видимость с помощью компонентов графического интерфейса.Если кто-нибудь знает лучший способ сделать это, пожалуйста, дайте мне знать.
Спасибо!