How to put uigetfile data from Pushbutton into Listbox?

1 visualización (últimos 30 días)
Tyann Hardyn
Tyann Hardyn el 18 de Sept. de 2021
Editada: Tyann Hardyn el 18 de Sept. de 2021
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 comentario
Jan
Jan el 18 de Sept. de 2021
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);

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 18 de Sept. de 2021
Editada: Jan el 18 de Sept. de 2021
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
  1 comentario
Tyann Hardyn
Tyann Hardyn el 18 de Sept. de 2021
Editada: Tyann Hardyn el 18 de Sept. de 2021
Omg, you did it, that was Great. I just want to get the logic of GUI' code, and i know it by now....
Thank you so much, Sir Jans..
Actually, I want to show some loading file (from selected files) which want to be proceeded at my program in that listbox....

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by