필터 지우기
필터 지우기

How to load data into uitable via button in GUI using GUIDE

조회 수: 12 (최근 30일)
Matt
Matt 2017년 6월 28일
댓글: Mark M 2017년 7월 8일
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
Adam
Adam 2017년 6월 28일
편집: Adam 2017년 6월 28일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2017년 6월 28일
Matt - readtable returns a table which cannot be used to set the data within a uitable (as the error message indicates). Depending upon the data in your table, you can try converting it to a cell array or numeric array using table2cell or table2array respectively. Or, you can investigate using a different method to import your data from file. See Ways to Import Text Files for details.
  댓글 수: 3
Mark M
Mark M 2017년 7월 8일
Hello,
I am attempting to do something similar, but as a listbox. When the user selects an option in the listbox, I want to pull only a certain set of data from the Excel file into the uitable in my GUI. Is this possible?
Mark M
Mark M 2017년 7월 8일
I figured it out in my case. For those interested, since I already had the dataset I wanted loaded in earlier in my code, I simply needed to use the table2cell as shown:
a = get(handles.TuscSortStreetRating,'Value'); if (a==1) figure imshow('TestImage.jpg') street1 = 'TestBook.xlsx'; T = readtable(street1); C = table2cell(T);
data=(C);
set(handles.uitable1, 'Data', data);
guidata(hObject, handles);
Once the user selects the first option of the listbox, this pops up an image and loads in the requested data from the test excel file.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by