필터 지우기
필터 지우기

how to remove specific rows of columns

조회 수: 2 (최근 30일)
farfar
farfar 2017년 2월 27일
댓글: farfar 2017년 2월 27일
Hey everyone. I have one matrix [a] with 5 columns. i am removing some rows of b=a(:,4) based on some threshold, and then I need to construct a new matrix with the new column 4 . but I also need to include the first three columns. how can I remove the same rows from the first three columns? Thanks !

채택된 답변

James Tursa
James Tursa 2017년 2월 27일
편집: James Tursa 2017년 2월 27일
Save the indexing that you use to do the removing, and then apply that to the original matrix during the reconstruction. E.g.,
>> a = reshape(1:30,6,5)
a =
1 7 13 19 25
2 8 14 20 26
3 9 15 21 27
4 10 16 22 28
5 11 17 23 29
6 12 18 24 30
>> b = a(:,4)
b =
19
20
21
22
23
24
>> rows_to_remove = mod(b,2)==1
rows_to_remove =
1
0
1
0
1
0
>> result = [a(~rows_to_remove,1:3) b(~rows_to_remove)]
result =
2 8 14 20
4 10 16 22
6 12 18 24
Or suppose instead of logical indexing as in the above example, you had row numbers to remove. E.g.,
rows_to_remove = [1 3 5]
Then just transform this into a logical indexing vector first. E.g.,
rows_to_remove = ismember(1:size(a,1),rows_to_remove)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by