Hi, I need help to delete several rows of a table whose column has a zeros for example
column 1 column2
1 2
3 2
4 0
5 6
1 0
9 0
I need delete the rows number 3,5 and 6

 채택된 답변

Guillaume
Guillaume 2018년 5월 24일

3 개 추천

Assuming you indeed have a matlab table:
yourtable(yourtable.column2 == 0, :) = [];
will delete all rows whose column2 is 0.
If your table is actually a matrix:
yourmatrix(yourmatrix(:, 2) == 0, :) = [];
will do the same.

댓글 수: 1

Jessica Blasco
Jessica Blasco 2018년 5월 24일
thankssss!!!! it worksss!!! is what I wanted to do it!!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Alfonso
Alfonso 2018년 5월 24일
편집: Alfonso 2018년 5월 24일

1 개 추천

Try this
% define your table
table_array = [1 2; 3 2; 4 0; 5 6; 1 0; 9 0];
% search index rows
[index_row index_col] = find(table_array==0);
% delete
table_array( index_row, : ) = [];

댓글 수: 2

Guillaume
Guillaume 2018년 5월 24일
편집: Guillaume 2018년 5월 24일
Since you never use index_col, you can write:
[index_row, ~] = find(table_array == 0); %force the two output version of find.
A simpler version of the whole lot:
table_array(any(table_array == 0, 2), :) = [];
My understanding however is that the 0s are only in column 2
Jessica Blasco
Jessica Blasco 2018년 5월 24일
thank you very much, it works to matrix very well, buy I have a table. First of all , I had table2array, but later, other partner said me the solution by tables!
even so, thanks! good job!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

태그

질문:

2018년 5월 24일

댓글:

2018년 5월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by