Delete rows of excel if any empty cell found

1 vue (au cours des 30 derniers jours)
Adi Purwandana
Adi Purwandana le 13 Oct 2023
Dear everyone,
I have an excel file containing some Stations defined in the first column (attached). Here, as shown below, I have 4 stations. Some stations contain no value (empty cell) like Station 1; and some stations not all cells have values.
Does anyone know how to delete the row if there's any cell with no value detected? In this case, there will be 3 stations left and the rows with empty cells in those 3 stations will be omited :
best regards
  3 commentaires
Walter Roberson
Walter Roberson le 13 Oct 2023
I do not see any height information in that table?
If you are trying to sort by depth see sortrows
Adi Purwandana
Adi Purwandana le 13 Oct 2023
Modifié(e) : Adi Purwandana le 13 Oct 2023
Thank you for your response @Walter Roberson. Here is what I want:
Attached file is the excel file. So, it must be ordered from the shorter (shallower) station to the longer one and so on... Any suggestions? I tried using sortrows but it doesn't solve.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 13 Oct 2023
I am not certain how you want to sort the ‘Station’ by ‘shortest to the longest’.
Try this —
T1 = readtable('datax.xlsx', 'VariableNamingRule','preserve')
T1 = 24×9 table
Station Lon Lat Depth Salinity Temperature u v yyyy-mm-ddThh:mm:ss.sss _______ ______ _____ _____ ________ ___________ _____ ______ _______________________ 1 114.8 -8.16 0 NaN NaN NaN NaN {'2023-10-08T00:00:00'} 1 114.8 -8.16 2 NaN NaN NaN NaN {'2023-10-08T00:00:00'} 1 114.8 -8.16 4 NaN NaN NaN NaN {'2023-10-08T00:00:00'} 1 114.8 -8.16 6 NaN NaN NaN NaN {'2023-10-08T00:00:00'} 1 114.8 -8.16 8 NaN NaN NaN NaN {'2023-10-08T00:00:00'} 1 114.8 -8.16 10 NaN NaN NaN NaN {'2023-10-08T00:00:00'} 2 114.88 -8.16 0 33.981 29.324 0.11 -0.017 {'2023-10-08T00:00:00'} 2 114.88 -8.16 2 33.979 29.248 0.106 -0.011 {'2023-10-08T00:00:00'} 2 114.88 -8.16 4 33.979 29.25 0.106 -0.011 {'2023-10-08T00:00:00'} 2 114.88 -8.16 6 33.978 29.251 0.105 -0.011 {'2023-10-08T00:00:00'} 2 114.88 -8.16 8 33.978 29.251 0.105 -0.011 {'2023-10-08T00:00:00'} 2 114.88 -8.16 10 NaN NaN NaN NaN {'2023-10-08T00:00:00'} 3 114.96 -8.16 0 33.995 29.171 0.109 -0.037 {'2023-10-08T00:00:00'} 3 114.96 -8.16 2 33.992 29.108 0.104 -0.03 {'2023-10-08T00:00:00'} 3 114.96 -8.16 4 33.992 29.11 0.102 -0.03 {'2023-10-08T00:00:00'} 3 114.96 -8.16 6 33.992 29.114 0.102 -0.03 {'2023-10-08T00:00:00'}
T1{:,end} = cellfun(@(x)datetime(x, 'InputFormat','yyyy-MM-dd''T''HH:mm:ss', 'Format','yyyy-MM-dd HH:mm:ss'), T1{:,end}, 'Unif',0)
T1 = 24×9 table
Station Lon Lat Depth Salinity Temperature u v yyyy-mm-ddThh:mm:ss.sss _______ ______ _____ _____ ________ ___________ _____ ______ _______________________ 1 114.8 -8.16 0 NaN NaN NaN NaN {[2023-10-08 00:00:00]} 1 114.8 -8.16 2 NaN NaN NaN NaN {[2023-10-08 00:00:00]} 1 114.8 -8.16 4 NaN NaN NaN NaN {[2023-10-08 00:00:00]} 1 114.8 -8.16 6 NaN NaN NaN NaN {[2023-10-08 00:00:00]} 1 114.8 -8.16 8 NaN NaN NaN NaN {[2023-10-08 00:00:00]} 1 114.8 -8.16 10 NaN NaN NaN NaN {[2023-10-08 00:00:00]} 2 114.88 -8.16 0 33.981 29.324 0.11 -0.017 {[2023-10-08 00:00:00]} 2 114.88 -8.16 2 33.979 29.248 0.106 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 4 33.979 29.25 0.106 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 6 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 8 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 10 NaN NaN NaN NaN {[2023-10-08 00:00:00]} 3 114.96 -8.16 0 33.995 29.171 0.109 -0.037 {[2023-10-08 00:00:00]} 3 114.96 -8.16 2 33.992 29.108 0.104 -0.03 {[2023-10-08 00:00:00]} 3 114.96 -8.16 4 33.992 29.11 0.102 -0.03 {[2023-10-08 00:00:00]} 3 114.96 -8.16 6 33.992 29.114 0.102 -0.03 {[2023-10-08 00:00:00]}
T1 = rmmissing(T1)
T1 = 15×9 table
Station Lon Lat Depth Salinity Temperature u v yyyy-mm-ddThh:mm:ss.sss _______ ______ _____ _____ ________ ___________ _____ ______ _______________________ 2 114.88 -8.16 0 33.981 29.324 0.11 -0.017 {[2023-10-08 00:00:00]} 2 114.88 -8.16 2 33.979 29.248 0.106 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 4 33.979 29.25 0.106 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 6 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 8 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]} 3 114.96 -8.16 0 33.995 29.171 0.109 -0.037 {[2023-10-08 00:00:00]} 3 114.96 -8.16 2 33.992 29.108 0.104 -0.03 {[2023-10-08 00:00:00]} 3 114.96 -8.16 4 33.992 29.11 0.102 -0.03 {[2023-10-08 00:00:00]} 3 114.96 -8.16 6 33.992 29.114 0.102 -0.03 {[2023-10-08 00:00:00]} 4 115.04 -8.16 0 33.992 29.273 0.048 0.005 {[2023-10-08 00:00:00]} 4 115.04 -8.16 2 33.988 29.264 0.05 0.009 {[2023-10-08 00:00:00]} 4 115.04 -8.16 4 33.988 29.266 0.052 0.009 {[2023-10-08 00:00:00]} 4 115.04 -8.16 6 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]} 4 115.04 -8.16 8 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]} 4 115.04 -8.16 10 33.987 29.259 0.048 0.01 {[2023-10-08 00:00:00]}
Stations = accumarray(T1{:,1}, (1:size(T1,1)).', [], @(x){T1(x,:)})
Stations = 4×1 cell array
{0×0 double} {5×9 table } {4×9 table } {6×9 table }
[sz,ix] = sort(cellfun(@(x)size(x,1), Stations));
valid = [sz(sz~=0) ix(sz~=0)]
valid = 3×2
4 3 5 2 6 4
Stations_Sorted = cat(1,Stations{valid(:,2)}) % Reordered
Stations_Sorted = 15×9 table
Station Lon Lat Depth Salinity Temperature u v yyyy-mm-ddThh:mm:ss.sss _______ ______ _____ _____ ________ ___________ _____ ______ _______________________ 3 114.96 -8.16 0 33.995 29.171 0.109 -0.037 {[2023-10-08 00:00:00]} 3 114.96 -8.16 2 33.992 29.108 0.104 -0.03 {[2023-10-08 00:00:00]} 3 114.96 -8.16 4 33.992 29.11 0.102 -0.03 {[2023-10-08 00:00:00]} 3 114.96 -8.16 6 33.992 29.114 0.102 -0.03 {[2023-10-08 00:00:00]} 2 114.88 -8.16 0 33.981 29.324 0.11 -0.017 {[2023-10-08 00:00:00]} 2 114.88 -8.16 2 33.979 29.248 0.106 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 4 33.979 29.25 0.106 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 6 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]} 2 114.88 -8.16 8 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]} 4 115.04 -8.16 0 33.992 29.273 0.048 0.005 {[2023-10-08 00:00:00]} 4 115.04 -8.16 2 33.988 29.264 0.05 0.009 {[2023-10-08 00:00:00]} 4 115.04 -8.16 4 33.988 29.266 0.052 0.009 {[2023-10-08 00:00:00]} 4 115.04 -8.16 6 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]} 4 115.04 -8.16 8 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]} 4 115.04 -8.16 10 33.987 29.259 0.048 0.01 {[2023-10-08 00:00:00]}
.
  10 commentaires
Adi Purwandana
Adi Purwandana le 15 Oct 2023
Thank you @Star Strider for completing the solution!
Star Strider
Star Strider le 15 Oct 2023
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Downloads dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by