How to display different columns from excel file using uitable on MATLAB GUI?
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Geoff Hayes
on 26 Sep 2015
Edited: Geoff Hayes
on 26 Sep 2015
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 Comments
Geoff Hayes
on 27 Sep 2015
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.
See Also
Categories
Find more on Spreadsheets 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!