I have a training label for 3 different classes in a matrix of size 1*178 example t=[1 1 1 3 1 2 3 1 ... .....]. Anyone please help me to write an efficient code for generating a new matrix of size 3*178 where based on the value in "t", the corresponding location in columns should be 1.
for the above example. the output will be like the following matrix:
[1 1 1 0 1 0 0 1.... 0 0 0 0 0 1 0 0..... 0 0 0 1 0 0 1 0.....]

 채택된 답변

Walter Roberson
Walter Roberson 2016년 2월 24일

2 개 추천

[t(:) == 1, t(:) == 2, t(:) == 3]

추가 답변 (1개)

Stephen23
Stephen23 2016년 2월 24일
편집: Stephen23 2016년 2월 24일

0 개 추천

For a simple generalized solution use bsxfun:
>> t = [1 1 1 3 1 2 3 1]
>> bsxfun(@eq,(1:3).',t)
ans =
1 1 1 0 1 0 0 1
0 0 0 0 0 1 0 0
0 0 0 1 0 0 1 0

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

Jab
2016년 2월 24일

편집:

2016년 2월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by