vector of random natural numbers to matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Thomas Kozinski
am 12 Mär. 2021
Beantwortet: David Hill
am 12 Mär. 2021
Hello, I have a problem with the task, if someone could direct me / tell me how to do it
I have to do:
Create a 100-element vector of random positive numbers and then write it as a matrix with the number of rows equal to the number of unique numbers in the vector and 100 columns
and then to each element of the original vector encode its value as 1 in the field with index equal to the value of this element (one-hot encoding).
Thanks in advance!!!
2 Kommentare
Akzeptierte Antwort
David Hill
am 12 Mär. 2021
a=randi(100,1,100);
b=unique(a);
c=zeros(length(b),100);
for k=1:length(b)
c(k,:)=a==b(k);
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!