Delete rows of excel if any empty cell found
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2023-10-13
I do not see any height information in that table?
If you are trying to sort by depth see sortrows
Adi Purwandana
2023-10-13
编辑:Adi Purwandana
2023-10-13
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.
采纳的回答
Star Strider
2023-10-13
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 个评论
Adi Purwandana
2023-10-13
编辑:Adi Purwandana
2023-10-13
Aha! @Star Strider exactly what I want. Anyway, is there any line I should add to re-numbering the column of Station number?
Station 3 --> Station 1
Station 2 --> Station 2
Station 4 --> Station 3
Thanks
Star Strider
2023-10-13
As always, my pleasure!
I was away for a few minutes. That is exactly the approach I would have taken!
Adi Purwandana
2023-10-13
编辑:Adi Purwandana
2023-10-13
Maybe my last question following this thread @Star Strider, do you know the way to omit the stations with the Depth layer less than a certain depth?
For example in this datasets:
Station 1 --> has 4 layers (0 m, 2 m, 4, 6);
Station 2 --> has 5 layers (0, 2, 4, 6, 8,)
Station 3 --> has 6 layers
For example, my purpose is... excluding the Stations with depth of less than 8 m depth; so that the Station 2 and Station 1 will be omited from the Stations_Sorted. So, there will be Stations with depth layer > 8 m (in this case is only Station 3) inside Stations_Sorted.
Thank you!
Star Strider
2023-10-14
This will delete ‘Station’ table arrays with no ‘Depth’ value greater than 8 and will retain ‘Station’ table arrays with at least one ‘Depth’ value greater than 8, regardless of what the other ‘Depth’ values are. It also re-numbers the stations after using rmmissing so they begin at 1.
The revised version —
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]}
[Su,~,s] = unique(T1.Station,'stable');
T1.Station = s % Renumber 'Station'
T1 = 15×9 table
Station Lon Lat Depth Salinity Temperature u v yyyy-mm-ddThh:mm:ss.sss
_______ ______ _____ _____ ________ ___________ _____ ______ _______________________
1 114.88 -8.16 0 33.981 29.324 0.11 -0.017 {[2023-10-08 00:00:00]}
1 114.88 -8.16 2 33.979 29.248 0.106 -0.011 {[2023-10-08 00:00:00]}
1 114.88 -8.16 4 33.979 29.25 0.106 -0.011 {[2023-10-08 00:00:00]}
1 114.88 -8.16 6 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]}
1 114.88 -8.16 8 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]}
2 114.96 -8.16 0 33.995 29.171 0.109 -0.037 {[2023-10-08 00:00:00]}
2 114.96 -8.16 2 33.992 29.108 0.104 -0.03 {[2023-10-08 00:00:00]}
2 114.96 -8.16 4 33.992 29.11 0.102 -0.03 {[2023-10-08 00:00:00]}
2 114.96 -8.16 6 33.992 29.114 0.102 -0.03 {[2023-10-08 00:00:00]}
3 115.04 -8.16 0 33.992 29.273 0.048 0.005 {[2023-10-08 00:00:00]}
3 115.04 -8.16 2 33.988 29.264 0.05 0.009 {[2023-10-08 00:00:00]}
3 115.04 -8.16 4 33.988 29.266 0.052 0.009 {[2023-10-08 00:00:00]}
3 115.04 -8.16 6 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]}
3 115.04 -8.16 8 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]}
3 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,:)}); % Segment Table By Station
% Stations = Stations(cellfun(@(x)~isempty(x), Stations)) % Delete Empty Cells
Lv = cellfun(@(x)any(x.Depth > 8), Stations); % Logical Vector To Select Cells With At Least One 'Depth' > 8
Stations = Stations(Lv); % Select Cells With At Least One 'Depth' > 8
[sz,ix] = sort(cellfun(@(x)size(x,1), Stations)); % Sort By Row Size
Stations_Sorted = cat(1,Stations{ix}) % Reordered
Stations_Sorted = 6×9 table
Station Lon Lat Depth Salinity Temperature u v yyyy-mm-ddThh:mm:ss.sss
_______ ______ _____ _____ ________ ___________ _____ _____ _______________________
3 115.04 -8.16 0 33.992 29.273 0.048 0.005 {[2023-10-08 00:00:00]}
3 115.04 -8.16 2 33.988 29.264 0.05 0.009 {[2023-10-08 00:00:00]}
3 115.04 -8.16 4 33.988 29.266 0.052 0.009 {[2023-10-08 00:00:00]}
3 115.04 -8.16 6 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]}
3 115.04 -8.16 8 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]}
3 115.04 -8.16 10 33.987 29.259 0.048 0.01 {[2023-10-08 00:00:00]}
.
Adi Purwandana
2023-10-14
Great as always!
My curious question... If I want to re-numbering the stations again (here for example I only consider the station with depth >6m), it gives:
Do you know the line I should modify if I want to re-numbering the stations again, so that:
Station 1 --> Station 1
Station 3 --> Station 2
Thank you!
Adi Purwandana
2023-10-14
Solved, sorry!
[Su,~,s] = unique(Stations_Sorted.Station,'stable');
Stations_Sorted.Station = s;
Star Strider
2023-10-14
Thank you!
As always, my pleasure!
The only thing that comes to mind is to mpve these assignments:
[Su,~,s] = unique(T1.Station,'stable');
T1.Station = s % Renumber 'Station'
to later in the code.
This re-numbers them and then re-sorts them —
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]}
% [Su,~,s] = unique(T1.Station,'stable');
% T1.Station = s % Renumber 'Station'
Stations = accumarray(T1{:,1}, (1:size(T1,1)).', [], @(x){T1(x,:)}) % Segment Table By Station
Stations = 4×1 cell array
{0×0 double}
{5×9 table }
{4×9 table }
{6×9 table }
Stations = Stations(cellfun(@(x)~isempty(x), Stations)) % Delete Empty Cells
Stations = 3×1 cell array
{5×9 table}
{4×9 table}
{6×9 table}
Lv = cellfun(@(x)any(x.Depth > 6), Stations) % Logical Vector To Select Cells With At Least One 'Depth' > 8
Lv = 3×1 logical array
1
0
1
Stations = Stations(Lv); % Select Cells With At Least One 'Depth' > 8
Stations
Stations = 2×1 cell array
{5×9 table}
{6×9 table}
[sz,ix] = sort(cellfun(@(x)size(x,1), Stations)); % Sort By Row Size
Stations_Sorted = cat(1,Stations{ix}) % Reordered
Stations_Sorted = 11×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]}
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]}
[Su,~,s] = unique(Stations_Sorted.Station,'stable');
Stations_Sorted.Station = s % Renumber 'Station'
Stations_Sorted = 11×9 table
Station Lon Lat Depth Salinity Temperature u v yyyy-mm-ddThh:mm:ss.sss
_______ ______ _____ _____ ________ ___________ _____ ______ _______________________
1 114.88 -8.16 0 33.981 29.324 0.11 -0.017 {[2023-10-08 00:00:00]}
1 114.88 -8.16 2 33.979 29.248 0.106 -0.011 {[2023-10-08 00:00:00]}
1 114.88 -8.16 4 33.979 29.25 0.106 -0.011 {[2023-10-08 00:00:00]}
1 114.88 -8.16 6 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]}
1 114.88 -8.16 8 33.978 29.251 0.105 -0.011 {[2023-10-08 00:00:00]}
2 115.04 -8.16 0 33.992 29.273 0.048 0.005 {[2023-10-08 00:00:00]}
2 115.04 -8.16 2 33.988 29.264 0.05 0.009 {[2023-10-08 00:00:00]}
2 115.04 -8.16 4 33.988 29.266 0.052 0.009 {[2023-10-08 00:00:00]}
2 115.04 -8.16 6 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]}
2 115.04 -8.16 8 33.988 29.267 0.052 0.009 {[2023-10-08 00:00:00]}
2 115.04 -8.16 10 33.987 29.259 0.048 0.01 {[2023-10-08 00:00:00]}
.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)