How to sort excel data to be displayed on uitable in MATLAB GUI?

1 view (last 30 days)
Good day! Given that I have an excel file that contains data, I would like to ask on how to sort the data from the excel file and be displayed on MATLAB GUI uitable in a/an descending/ascending order?
For an example (the data from the excel file are separated by ';' on my illustration, which means that there are 5 cells involved per row), column 5 needs to be sorted:
Row 1: NAME1 ; 1 ; 1 ; 0 ; 2.
Row 2: NAME2 ; 1 ; 2 ; 2 ; 5.
Row 3: NAME3 ; 1 ; 2 ; 1 ; 4.
Row 4: NAME4 ; 0 ; 2 ; 1 ; 3.
Row 5: NAME5 ; 0 ; 0 ; 1 ; 1.
How can the data be displayed in a/an descending/ascending order on the uitable of the MATLAB GUI like this while a static text box displays NAME2, NAME3, and NAME4 are the first 3 rows after sorting was applied?
Row 1: NAME2 ; 1 ; 2 ; 2 ; 5.
Row 2: NAME3 ; 1 ; 2 ; 1 ; 4.
Row 3: NAME4 ; 0 ; 2 ; 1 ; 3.
Row 4: NAME1 ; 1 ; 1 ; 0 ; 2.
Row 5: NAME5 ; 0 ; 0 ; 1 ; 1.
Thank you so much.

Answers (1)

Finn Meissner
Finn Meissner on 1 Sep 2015
Good Day to you too! This might help you to import and Sort the Data, but to display it properly aditionall information about the GUI is needed (as table, as string, just the names or numbers in a specif way,....)
% [num,txt,raw,custom] = xlsread(filename,sheet,xlRange,'',processFcn)
% as the Data is text and numbers i prefer 'raw', if you have multiple sheets or just need a specific part of the sheet you can use the additional parameters, if not
[~,~,Data] = xlsread('ExcelFile.xlsx');
[~,order] = sort([Data{:,5}],'descend'); % be aware of the different bracket used
Datasorted=Data(order,:); %if you dont need the unsorted just go for Data=Data(order,:);
Datasorted %displys the now sorted Data

Community Treasure Hunt

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

Start Hunting!