Removing a row from a matrix based on certain conditions

24 ビュー (過去 30 日間)
Yaser Khojah
Yaser Khojah 2019 年 1 月 26 日
コメント済み: Yaser Khojah 2019 年 1 月 26 日
I have three variables t_SS, t_A, and G and all of them have the size of 10000 X 8. I'm looking for away to remove the entire row in G if any of the following coniditions is met. Below is my code and does not work properly since if G is deleted in the first conidtion, the number of index change.
Not sure how to fix it and thanks in advance.
Index_N_tS = find(t_SS < 0);
Index_N_tA = find(t_A < 0);
Index_less_A = find(t_A < t_SS);
I have to check these cells are not empty:
indx1_tS = isempty(Index_N_tS);
indx1_tS = isempty(Index_N_tS);
indx3_tA = isempty(Index_less_A)
% if any of the condition is met, remove the entire row in G
if indx1_tS == 0
G(Index_N_tS ,:) = [];
end
if indx2_tA == 0
G(Index_N_tA,:) = [];
end
if indx3_tA == 0
G(Index_less_A,:) = [];
end
Thank you

採用された回答

Stephen23
Stephen23 2019 年 1 月 26 日
編集済み: Stephen23 2019 年 1 月 26 日
You do not explain how you want to handle the 8 columns in your logical comparisons: do you only want to remove the entire row if any column meets that condition, or if all columns meet that condition?
Here is a solution that works for any column meeting those conditions:
idx = any(t_SS < 0 | t_A < 0 | t_A < t_SS, 2);
G(idx,:) = []
You will need to decide if any or all or some other column handling is what you need.
  2 件のコメント
Yaser Khojah
Yaser Khojah 2019 年 1 月 26 日
so if any of the condition met, I will remove the entire row which means all the columns.
Yaser Khojah
Yaser Khojah 2019 年 1 月 26 日
Thank you so much Stephen for your help :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeANOVA についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by