Loop through data from Listbox
Afficher commentaires plus anciens
I have GUI which loads name of excel files inside listbox. Now I want a loop which can go through each file in the listbox and read the data. directory of files may not be same. xlsread can be used
function pushbuttonLoadfiles_Callback(hObject, eventdata, handles)
[filename,pathname,filterindex] = uigetfile('*.xls;*.xlsx;*.xlsm;*.xlsb', 'Multiselect', 'on');
set(handles.listboxExcelfiles,'string',filename);
function pushbuttonExtract_Callback(hObject, eventdata, handles)
source_files = numel(get(handles.listboxExcelfiles,'value'));
len = length(source_files);
for i = 1 : len
[~ , sheets] = xlsfinfo(source_files(i));
sheetIndex = find(strncmp(sheets, '~', 1));
wanted_sheets = sheets(1, sheetIndex);
set(handles.listboxDatasheets, 'string',wanted_sheets);
end
But here I get this error-
Error using xlsfinfo (line 39)
Filename must be a character vector.
Error in colordefined>pushbuttonExtract_Callback (line 154)
[~ , sheets] = xlsfinfo(source_files(i));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in colordefined (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)colordefined('pushbuttonExtract_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!