필터 지우기
필터 지우기

Delete and merge rows and columns based on values of other matrix

조회 수: 2 (최근 30일)
vimal r
vimal r 2020년 2월 21일
댓글: Guillaume 2020년 2월 24일
suppose consider a matrix of A = [1 2 3 4 ; 5 6 7 8 ; 9 1 2 3 ; 1 2 3 4] consider matrix B = [ 1 0 2 4 ]
so in matrix B value of 2 unit is 0 so i need to delete second row and second column in matrix A
final A1 matrix = [1 3 4 ; 9 2 3 ; 1 3 4]

채택된 답변

Sindar
Sindar 2020년 2월 21일
If I understand correctly:
  • You have one NxN matrix A
  • And a second 1xN vector B
  • When an element of B is zero, you delete rows and columns from A with the same index
A = [1 2 3 4 ; 5 6 7 8 ; 9 1 2 3 ; 1 2 3 4];
B = [ 1 0 2 4 ];
% find where B is nonzero
idx = find(B~=0);
% copy corresponding rows and columns of A to A1
A1=A(idx,idx);
  댓글 수: 7
vimal r
vimal r 2020년 2월 24일
so how to solve without looping it by individually...??
Guillaume
Guillaume 2020년 2월 24일
I'm not sure which of your 3 questions the above refers to. You would be better off starting a new question for each topic.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by