필터 지우기
필터 지우기

Creating a new matrix from two matrixes

조회 수: 1 (최근 30일)
Moe
Moe 2014년 10월 29일
답변: James Tursa 2014년 10월 29일
Suppose I have a matrix a:
a = [9,1;1,1;3,1;2,1;5,1;6,1;8,1;1,1;2,1;5,1;8,1;2,1];
And I have another matrix b which is like some selected index number of matrix a:
b = [4;10;7]; % for example 4 means forth row in matrix a which is (2,1) here
So, I need to have a new matrix c in that way present those rows in matrix a which are indicated in matrix b and others array be equal to 0:
c = [0,0;0,0;0,0;2,1;0,0;0,0;8,1;0,0;0,0;5,1;0,0;0,0;]; % for example forth row is (2,1) because 4 row is presented in matrix b

채택된 답변

James Tursa
James Tursa 2014년 10월 29일
c = zeros(size(a));
c(b,:) = a(b,:);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by