How to load data into uitable via button in GUI using GUIDE
Show older comments
I'm currently creating a GUI using GUIDE (which I am relatively new to). I would like to be able to get the end user to select a .csv file to load into the GUI and for it to be displayed in a table. So far, I am using the following code:
function loadBtn_Callback(hObject, eventdata, handles)
% hObject handle to loadBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname]=uigetfile({'*.csv'}, 'Select File');
if isequal(filename,0)
return
else
Path=strcat(pathname,filename);
data=readtable(Path, 'Delimiter', ';');
set(handles.data_table, 'Data', data);
end
guidata(hObject, handles);
However, I keep getting the following error:
Error using matlab.ui.control.Table/set
While setting the 'Data' property of 'Table':
Data must be a numeric, logical, or cell array
I've tried running this same code in a normal script and it works fine, what am I doing wrong?
1 Comment
readtable
reads into a table data structure object, but unfortunately these (being relatively recent additions) are not supported by uitable so you have to load your data into a cell array or numeric array to feed it to uitable.
I never use csv files or tables though so someone else can hopefully advise better on how to get the data loaded in.
doc csvread
should give you a numeric matrix I think.
Accepted Answer
More Answers (0)
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!