Populate columns of matrix without for loop using input from a vector of intergers
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Michael Devereux
am 7 Jul. 2017
Beantwortet: Greg Heath
am 7 Jul. 2017
I am looking for a way to generate a target matrix for the neural network toolbox using labeled data where each class is represented in an vector of integers.
Example:
X =
[0
2
1
2
3]
I need this in the form
X = [ 1 0 0 0
0 0 1 0
0 1 0 0
0 0 1 0
0 0 0 1]
Is it possible to do this without a loop?
Thanks
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Greg Heath
am 7 Jul. 2017
>> clear all
classindices = [1 3 5 4 2 ];
classmatrix = full(ind2vec(classindices))
classmatrix =
1 0 0 0 0
0 0 0 0 1
0 1 0 0 0
0 0 0 1 0
0 0 1 0 0
Hope this helps.
Greg
0 Kommentare
Siehe auch
Kategorien
Mehr zu Sequence and Numeric Feature Data Workflows finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!