필터 지우기
필터 지우기

How to convert a row vector into desired matrix?

조회 수: 2 (최근 30일)
MANISH KUMAR
MANISH KUMAR 2017년 2월 22일
댓글: MANISH KUMAR 2017년 2월 22일
For example, we have a row vector A
A = [ 4 3 6 2 5];
And I want to convert this row vector into a matrix of '5 X 7' containing zeros and ones only. Required matrix is
% Matrix A
A = [0 0 0 1 0 0 0
0 0 1 0 0 0 0
0 0 0 0 0 1 0
0 1 0 0 0 0 0
0 0 0 0 1 0 0]
Every elment of the row vector represents the position of '1' in each row of the matrix.
Guys, please help me in getting the solution to this problem.

채택된 답변

KSSV
KSSV 2017년 2월 22일
iwant = zeros(length(A),max(A)) ;
for i = 1:length(A)
iwant(i,A(i))=1;
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 2월 22일
편집: Walter Roberson 2017년 2월 22일

카테고리

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