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

1 回表示 (過去 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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by