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

3 次查看(过去 30 天)
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.

采纳的回答

Voss
Voss 2022-7-2
编辑:Voss 2022-7-2
% (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) = [];

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by