How to convert a row vector into desired matrix?

3 ビュー (過去 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 件のコメント
MANISH KUMAR
MANISH KUMAR 2017 年 2 月 22 日
Thank you very much for this kind support.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 2 月 22 日
編集済み: Walter Roberson 2017 年 2 月 22 日

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by