Azzera filtri
Azzera filtri

How to remove 0 (for 'double' numerical type) or [] (for cell type) rows in a table ?

3 visualizzazioni (ultimi 30 giorni)
Sorry I am new to matlab ! Any help would be really appreciated ! Have a nice evening !
Ps: I tried the function unique but and as usual on matlab, it doesn't work. I guess its because there are two types in the table ('cell' for bankname and 'double' for the other categories).

Risposte (1)

Giovanni Mottola
Giovanni Mottola il 13 Nov 2016
Starting point:
tab =
S_Bankname S_CommonEquityTierRatio_2013 S_Log_TotalAssets_2013
__________ ____________________________ ______________________
'' 0.00000000000000e+00 0.00000000000000e+00
'Axa' 1.14661000000000e+00 1.08520000000000e+01
'Carige' 3.90410000000000e-02 1.07440000000000e+01
'MPS' 6.98750000000000e-02 1.23110000000000e+01
'' 0.00000000000000e+00 0.00000000000000e+00
'Cyprus' 7.28620000000000e-02 1.03870000000000e+01
Assuming that the rows to delete have 0 in the second column:
toDelete = tab.S_CommonEquityTierRatio_2013==0;
tab(toDelete,:) = [];
Final result:
tab =
S_Bankname S_CommonEquityTierRatio_2013 S_Log_TotalAssets_2013
__________ ____________________________ ______________________
'Axa' 1.14661000000000e+00 1.08520000000000e+01
'Carige' 3.90410000000000e-02 1.07440000000000e+01
'MPS' 6.98750000000000e-02 1.23110000000000e+01
'Cyprus' 7.28620000000000e-02 1.03870000000000e+01
  4 Commenti
Giovanni Mottola
Giovanni Mottola il 14 Nov 2016
Modificato: Giovanni Mottola il 14 Nov 2016
I just tried the code you wrote with the initial data as follows:
S_Bankname={'', 'Axa', 'Carige', 'MPS', '', 'Cyprus'}.';
S_CommonEquityTier1Ratio_2013=[0, 1.14661, 0.039041, 0.069875, 0, 0.072862].';
S_Log_TotalAssets_2013=[0, 10.852, 10.744, 12.311, 0, 10.387].';
I used only a subset of your table to keep things simple.
Using the commands you wrote, that is,
S_Test_Table=table(S_Bankname,S_CommonEquityTier1Ratio_2013,S_Log_TotalAssets_2013)
toDelete = S_Test_Table.S_CommonEquityTier1Ratio_2013==0;
S_Test_Table(toDelete,:) = [];
the table does change and the empty lines are deleted.
Could it be that, in your table, the "empty" rows don't actually have zeros in the second column but instead very small values? Could you provide the full data for your table?
Walter Roberson
Walter Roberson il 14 Nov 2016
Deleting a row in a table works fine.
a = randi(6,3,1); b = {'hello';'';'zumba'};
t = table(a,b);
toDelete = cellfun(@isempty,t.b);
t(toDelete,:) = [];

Accedi per commentare.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by