How do i select some columns that have maximum some values ?

1 vue (au cours des 30 derniers jours)
ahmed obaid
ahmed obaid le 3 Avr 2017
Modifié(e) : ahmed obaid le 4 Avr 2017
Dear experiences
i have a data look like at the following in an excel file called (data.xls)
obs-name Var1 var2 var3 ..... varn
obs1 0.09 0.23 0.0 0.03
obs2 0.21 0.0 0.2 0.4
etc...
  • - i need to calculate the averages of variables values across all observation names ( every var column is independent from others).
  • - then eliminate all columns except (k) columns that have (k) largest average values ...
  • - for example if k=5 then result includes only observation names and 5 columns that involve largest 5 average values?
thanks for any participation ...

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 3 Avr 2017
T = readtable('data.xlsx');
dm = mean(T{:,2:end});
[~,ii] = sort(dm,'descend');
k = 2; % Let k = 2
Tout = T(:,[1,sort(ii(1:k)+1)]);
  2 commentaires
ahmed obaid
ahmed obaid le 3 Avr 2017
thank you a lot, very smart solution
ahmed obaid
ahmed obaid le 4 Avr 2017
Modifié(e) : ahmed obaid le 4 Avr 2017

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by