Deleting the column with zero values and corresponding columns from another matrix

3 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Voss
Voss am 2 Jul. 2022
Bearbeitet: Voss am 2 Jul. 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) = [];

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by