edgarmtze
edgarmtze

Reputation: 25058

generate n samples and tag them Matlab

How to generate n samples and tag with a number in other column.

I have this:

n= 5;
sample1= randn(n,1)
sample2= randn(n,1)

sample1 =

    0.3481
    0.2328
    0.6735
   -0.1274
   -0.4146


sample2 =

   -1.4964
   -0.7325
   -1.0193
   -0.6829
   -0.4427

I want

sample1 =

    0.3481  -1
    0.2328  -1
    0.6735  -1
   -0.1274  -1
   -0.4146  -1


sample2 =

   -1.4964  1
   -0.7325  1
   -1.0193  1
   -0.6829  1
   -0.4427  1

And in a matrix have all data:

data=
        0.3481  -1
        0.2328  -1
        0.6735  -1
       -0.1274  -1
       -0.4146  -1  
       -1.4964  1
       -0.7325  1
       -1.0193  1
       -0.6829  1
       -0.4427  1

How to do this?

Upvotes: 1

Views: 67

Answers (1)

KnowledgeBone
KnowledgeBone

Reputation: 1663

Try this:

n=5;
sample1=[randn(n,1) -1*ones(n,1)];
sample2=[randn(n,1) ones(n,1)];
data=[sample1; sample2];

Upvotes: 2

Related Questions