How to put uigetfile data from Pushbutton into Listbox?
3 次查看(过去 30 天)
显示 更早的评论
Hello Everyone,
Iam still new to GUI Logic of Matlab. I just want to get a logic code to set filename or uigetfile data into Listbox like this :

So, when the pushbutton contained with uigetfile code :
function loadekstrak_Callback(hObject, eventdata, handles)
% hObject handle to loadekstrak (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
push = guidata(gcbo);
[namafile,arah]=uigetfile({'*.txt', 'Text-Files (*.txt)'},'Load Data Magnet Format IAGA WDS (Definitif / Variatif)', 'Multiselect','on');
cd(arah);
full = fullfile(arah, namafile);
namafiles = cellstr(sort(namafile)); %Mensortir Kombinasi Data Yang Dipilih secara acak (PENTING)
fulls = string(full);
nfiles1 = size(full,2);
nfiles2 = numel(full);
f = cellstr(fullfile(arah,namafile));
file = length(f);
The callback function of listbox will add those information. And by using the code below, i am still get an error as the output :
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 = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
list = guidata(gcbo);
index_selected = get(handle.push,'Value');
list = get(hObject,'String');
item_selected = list{index_selected}; % Convert from cell array
% to string
Iam just trying to get information of " namafile " (filename from uigetfile) or "full" variable to be set into the listbox once the pushbutton was clicked and the data was selected respectively....
So anyone, would you mind to help me to find a logic for the code? I just dont understand if iam just read from the documentation.....
Thank you very much everyone /.\ /.\ /.\
1 个评论
Jan
2021-9-18
This part of the code does not do anything useful:
cd(arah);
full = fullfile(arah, namafile);
namafiles = cellstr(sort(namafile)); %Mensortir Kombinasi Data Yang Dipilih secara acak (PENTING)
fulls = string(full);
nfiles1 = size(full,2);
nfiles2 = numel(full);
f = cellstr(fullfile(arah,namafile));
file = length(f);
采纳的回答
Jan
2021-9-18
编辑:Jan
2021-9-18
I'm not sure what you want to achieve. With some guessing:
function loadekstrak_Callback(hObject, eventdata, handles)
% hObject handle to loadekstrak (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
push = guidata(gcbo);
[namafile,arah] = uigetfile({'*.txt', 'Text-Files (*.txt)'}, ...
'Load Data Magnet Format IAGA WDS (Definitif / Variatif)', ...
'Multiselect', 'on');
if isempty(namafile) % canceled
return;
end
push.listbox1.String = fullfile(ara, cellstr(namafile));
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!