vector of random natural numbers to matrix

조회 수: 3 (최근 30일)
Thomas Kozinski
Thomas Kozinski 2021년 3월 12일
답변: David Hill 2021년 3월 12일
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
Jan
Jan 2021년 3월 12일
What have you tried so far? What is your Matlab related question?
Adam Danz
Adam Danz 2021년 3월 12일
hint:
doc rand
doc randi
doc ismember
doc isequal

댓글을 달려면 로그인하십시오.

채택된 답변

David Hill
David Hill 2021년 3월 12일
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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by