How to put uigetfile data from Pushbutton into Listbox?
조회 수: 1 (최근 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!