Deleting the column with zero values and corresponding columns from another matrix
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 2 Jul 2022
Edited: Voss
on 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) = [];
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!