Я построил простой графический интерфейс, состоящий всего из двух popupmenu
с тегом: popupmenu1
и popupmenu2
.
popupmenu1
просто содержит некоторую строку, просто чтобы проверить код.
popupmenu2
содержит две строки: Save to default file
и Select a new file
Чтобы решить вашу проблему, вы можете добавить следующие строки кода во втором PopupMenu callback
.
Предлагаемое решение работает следующим образом:
, если он пользователь выбирает опцию кулака, то выход будет сохранен в выходном файле по умолчанию. Обратите внимание, что вы должны добавить код для фактического сохранения вывода в файле вывода по умолчанию
Если пользователь выбирает второй вариант, графический интерфейс uiputfile
просит пользователя определить/выбрать выходной файл. Некоторые проверки heve beem вставлены в файл selction. Кроме того, в этом случае, вы должны добавить код на самом деле сохранить вывод в файле вывод по умолчанию
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
% Identify the first popupm menu selected option
% not strictly necessary, just used to generare the messsage box text
sel_op=get(handles.popupmenu1,'value');
% Idetify the selected option in the second popupmenu
opt=get(hObject,'value')
% Test the second popup menu selection:
% if opt == 1: the default output file has been selected
if(opt == 1)
%
% Insert here the code to save the output in the default output file
%
msgbox(['Results of Operation #' num2str(sel_op) ' will be saved in the default output file'], ...
'Output file selection')
else
% if the second optino has been selected, the user is prompt to select the
% output file
[filename, pathname] = uiputfile(...
{'*.m';'*.mdl';'*.mat';'*.*'}, ...
'Save as');
% Check for the file selection
if(filename == 0)
msgbox('Output file selction aborted','Output file selection')
else
%
% Insert here the code to save the output in the user-defined
% output file
%
output_file_name=fullfile(pathname,filename)
msgbox(['Results of Operation #' num2str(sel_op) 'will be saved in ' output_file_name], ...
'Output file selection')
end
end
Надеется, что это помогает.
Отличный ответ. Большое вам спасибо за то, что поделились своими знаниями. – Maryam
Добро пожаловать! Счастлив, я был тебе полезен. –