В ссылке: [https://www.mathworks.com/help/matlab/creating_guis/interactive-list-box-in-a-guide-gui.html][1] Я могу создать приложение «Интерактивный список» в РУКОВОДСТВЕ
Я попытался добавить в конец function listbox1_Callback(hObject, eventdata, handles)
строку fullFileName = [path,name,ext]
, чтобы я мог получитьвывод пути, имени и расширения (например, F: /user/mySoft.m), но он не работает.Как я могу это сделать?
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
get(handles.figure1,'SelectionType');
if strcmp(get(handles.figure1,'SelectionType'),'open')
index_selected = get(handles.listbox1,'Value');
file_list = get(handles.listbox1,'String');
filename = file_list{index_selected}
[path,name,ext] = fileparts(filename)
fullFileName = [path, name, ext]
end
% ------------------------------------------------------------
% Read the current directory and sort the names
% ------------------------------------------------------------
function load_listbox(dir_path,handles)
cd (dir_path)
dir_struct = dir(dir_path);
[sorted_names,sorted_index] = sortrows({dir_struct.name}');
handles.file_names = sorted_names;
handles.is_dir = [dir_struct.isdir];
handles.sorted_index = sorted_index;
guidata(handles.figure1,handles)
set(handles.listbox1,'String',handles.file_names,...
'Value',1)
set(handles.text1,'String',pwd)
[1]: https://www.mathworks.com/help/matlab/creating_guis/interactive-list-box-in-a-guide-gui.html