How to display different columns from excel file using uitable on MATLAB GUI?
이전 댓글 표시
Good day! I would like to ask on how to display different columns from excel file using uitable on MATLAB GUI. I am planning to display columns B, D, and AV on the uitable (to be specific, the ranges are B2:B31, D2:31, and AV2:AV31). Uitable displays the data from excel using a push button.
I have tried the following codes but it displays the entire contents of the reference excel file. (I used Image Analyst's answer as reference from http://www.mathworks.com/matlabcentral/answers/119233-xlsread-for-many-distinct-columns-that-aren-t-side-by-side-in-the-ss)
function 1_Callback(hObject, eventdata, handles)
fileName = 'Database.xls';
[numbers,strings,raw] = xlsread(fileName);
colB = raw(2:31,2);
colD = raw(2:31,4);
colAV = raw(2:31,48);
set(handles.uitable1,'data',raw)
I also tried the following but I know it's obviously wrong.
function 1_Callback(hObject, eventdata, handles)
fileName = 'Database.xls';
[numbers,strings,raw] = xlsread(fileName, 'Total', 'B2:B31,D2:D31,AV2:AV31');%Total is the excel sheet name
set(handles.uitable1,'data',raw)
Can somebody suggest a way on how to assign different ranges of data from excel file to a singe uitable? Thank you.
답변 (1개)
Geoff Hayes
2015년 9월 26일
편집: Geoff Hayes
2015년 9월 26일
Mary - note the line of code that you are using to set the data within the uitable
set(handles.uitable1,'data',raw)
You are using raw rather than columns that you have extracted from raw. I suspect that you want something more like
set(handles.uitable1,'data',[colB colD colAV]);
Note how we concatenate the columns of interest using the square brackets.
댓글 수: 2
Mary Requilman
2015년 9월 27일
Geoff Hayes
2015년 9월 27일
Mary - presumably you have a push button that when pressed the data from the uitable will be saved to the Excel spreadsheet. So to get the data you would do something like
data = get(handles.uitable1,'data');
and then use http://www.mathworks.com/help/matlab/ref/xlswrite.html xlswrite> to write each column from data to the appropriate column in the spreadsheet. See the examples from the link.
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!