Deleting the column with zero values and corresponding columns from another matrix
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a 4 datasets with 1044 rows and 55 columns.
in one of the the dataset There are few columns which have negative values. (for any column which have negative values that i dont know)
I want to delete the column with the negative values and correspondingly i want to delete the same columns from the other three datasets.
Kindly suggest me how should i proceed with it.
0 Commenti
Risposta accettata
Voss
il 2 Lug 2022
Modificato: Voss
il 2 Lug 2022
% (1) data setup:
% 4 datasets (i.e., matrices) with 1044 rows and 55 columns:
M1 = rand(1044,55);
M2 = rand(1044,55);
M3 = rand(1044,55);
M4 = rand(1044,55);
% in one of the datasets, a few columns have negative values:
M2(:,[10 12 19 21 29]) = -M2(:,[10 12 19 21 29]);
% (2) delete the columns with negative values from all datasets:
% idx is a vector of logicals, saying whether
% each column in M2 has any negative values:
idx = any(M2 < 0,1);
% delete those columns from all datasets:
M1(:,idx) = [];
M2(:,idx) = [];
M3(:,idx) = [];
M4(:,idx) = [];
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!