How do I create a large binary target matrix?

4 vues (au cours des 30 derniers jours)
ampaul
ampaul le 14 Juin 2017
Commenté : Walter Roberson le 15 Juin 2017
Hello. I have a dataset of 300 samples (with 60 observations each) that are divided into 6 even categories (50 samples each)
For neural networking purposes, I would like to create a target matrix such that:
0-50 = category 1
51-50 = category 2
.
.
.
251-300 = category 6
I plan to assign these values by creating a 6x300 matrix. and placing a 1 in row 1 for 0-50, a 1 in row 2 for 51-100 and so on. I believe I may be able to do this by manipulating the eye function, but I have not seen examples of this. I know there must be an easier way to do this than by logging the numbers manually... any ideas? thanks

Réponse acceptée

Image Analyst
Image Analyst le 15 Juin 2017
Seems kind of weird, but going precisely by your directions, 6 lines of code should do it - one line of code for the 6 groups. Can't get much simpler or easier than that. See lines of code below, following your directions which are comments:
% creating a 6x300 matrix.
m = rand(6, 300);
% placing a 1 in row 1 for 0-50,
m(1, 1:50) = 1;
% a 1 in row 2 for 51-100,
m(2, 51:100) = 1;
% and so on
m(3, 101:150) = 1;
m(4, 151:200) = 1;
m(5, 201:250) = 1;
m(6, 251:300) = 1;
The only difference is I started at column 1 instead of 0 because there is no column 0.
  1 commentaire
ampaul
ampaul le 15 Juin 2017
Thank you. This worked

Connectez-vous pour commenter.

Plus de réponses (2)

Walter Roberson
Walter Roberson le 14 Juin 2017
Modifié(e) : Walter Roberson le 14 Juin 2017

Greg Heath
Greg Heath le 15 Juin 2017
The only way to use eye is
target = repmat(eye(6),50)
Otherwise start with
target = zeros(6,300)
then insert ones(1,50) into the correct locations.
Hope this helps.
Thank you for formally accepting my answer
Greg

Catégories

En savoir plus sur Deep Learning Toolbox 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