Effacer les filtres
Effacer les filtres

How to convert a row vector into desired matrix?

2 vues (au cours des 30 derniers jours)
MANISH KUMAR
MANISH KUMAR le 22 Fév 2017
Commenté : MANISH KUMAR le 22 Fév 2017
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.

Réponse acceptée

KSSV
KSSV le 22 Fév 2017
iwant = zeros(length(A),max(A)) ;
for i = 1:length(A)
iwant(i,A(i))=1;
end
  1 commentaire
MANISH KUMAR
MANISH KUMAR le 22 Fév 2017
Thank you very much for this kind support.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 22 Fév 2017
Modifié(e) : Walter Roberson le 22 Fév 2017

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by