フィルターのクリア

Delete specific rows from a matrix

3 ビュー (過去 30 日間)
Ron
Ron 2014 年 8 月 18 日
コメント済み: Joseph Cheng 2014 年 8 月 18 日
Hi all,
i want to delete rows which with the values 1 in their columns, how can i do it ?
For example:
A= [7,7;2,2;1,1;3,3]
Becomes
A=[7,7;2,2;3,3]
Thank you !
P.s I've searched other posts before posting this .. couldn't find any help

採用された回答

Joseph Cheng
Joseph Cheng 2014 年 8 月 18 日
編集済み: Joseph Cheng 2014 年 8 月 18 日
the use of the function any() can find where there are any numbers equal to one.
A= [7,7;2,2;1,1;3,3]
A(any(A==1,2),:)=[]
by using the dimension modifier in the any() function, i can return which rows or columns contain the logical 1 which is when A ==1.
  2 件のコメント
Ron
Ron 2014 年 8 月 18 日
Thank you ! what the '2' in the code line
A(any(A==1,2),:)=[]
stands for ?
Joseph Cheng
Joseph Cheng 2014 年 8 月 18 日
oh.. sorry meetings all day. the two is the dimension modifier. if you check the help for the any ('>>help any') the 2 stands for rows and 1 stands for columns. similar to the sum() function where you can sum a matrix in the row or column directions based on the dimension parameter.

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

その他の回答 (1 件)

Honglei Chen
Honglei Chen 2014 年 8 月 18 日
編集済み: Honglei Chen 2014 年 8 月 18 日
A(any(A==1,2),:) = []

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by