Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
-1 / +1 problem..

Subject: -1 / +1 problem..

From: Syed Galib

Date: 29 Jun, 2009 09:40:03

Message: 1 of 6

Hello all,

I am sorry to ask you again for another problem, as I am a new MATLab user.

I have a matrix, rAlphaSet with combinations of +1 and -1. I want to make 2 Matrices rAlpha1 and rAlpha2. I took 2 random numbers r1 and r2. Then I wanted to copy the r1th and r2th column of rAlphaSet to rAplha1 and rAlpha2. But the problem is, when I was running the code, rAlpha1 and rAlpha2 were not having the columns from rAlphaSet. Here is the code:

rAlphaSet = (npermutek([-1 1], 2^m))';
rAlpha1 = zeros(2^m,N);
rAlpha2 = zeros(2^m,N);

for i = 1:N
    r = randi(256,1);
    rAlpha1(:,i) = rAlphaSet(r);
    r = randi(256,1);
    rAlpha2(:,i) = rAlphaSet(r);
end

Can anybody tell me why this is happening? Please, help me.

Thank you very much in advance.

Regards
Galib

Subject: -1 / +1 problem..

From: us

Date: 29 Jun, 2009 09:52:01

Message: 2 of 6

"Syed Galib" <galib.cse@gmail.com> wrote in message <h2a25j$pr2$1@fred.mathworks.com>...
> Hello all,
>
> I am sorry to ask you again for another problem, as I am a new MATLab user.
>
> I have a matrix, rAlphaSet with combinations of +1 and -1. I want to make 2 Matrices rAlpha1 and rAlpha2. I took 2 random numbers r1 and r2. Then I wanted to copy the r1th and r2th column of rAlphaSet to rAplha1 and rAlpha2. But the problem is, when I was running the code, rAlpha1 and rAlpha2 were not having the columns from rAlphaSet. Here is the code:
>
> rAlphaSet = (npermutek([-1 1], 2^m))';
> rAlpha1 = zeros(2^m,N);
> rAlpha2 = zeros(2^m,N);
>
> for i = 1:N
> r = randi(256,1);
> rAlpha1(:,i) = rAlphaSet(r);
> r = randi(256,1);
> rAlpha2(:,i) = rAlphaSet(r);
> end
>
> Can anybody tell me why this is happening? Please, help me.
>
> Thank you very much in advance.
>
> Regards
> Galib

a hint:

% try
% ...
     rAlpha1(:,i)= rAlphaSet(:,r);
     rAlpha2(:,i)=rAlphaSet(:,r);
% ...

us

Subject: -1 / +1 problem..

From: us

Date: 29 Jun, 2009 09:52:01

Message: 3 of 6

"Syed Galib" <galib.cse@gmail.com> wrote in message <h2a25j$pr2$1@fred.mathworks.com>...
> Hello all,
>
> I am sorry to ask you again for another problem, as I am a new MATLab user.
>
> I have a matrix, rAlphaSet with combinations of +1 and -1. I want to make 2 Matrices rAlpha1 and rAlpha2. I took 2 random numbers r1 and r2. Then I wanted to copy the r1th and r2th column of rAlphaSet to rAplha1 and rAlpha2. But the problem is, when I was running the code, rAlpha1 and rAlpha2 were not having the columns from rAlphaSet. Here is the code:
>
> rAlphaSet = (npermutek([-1 1], 2^m))';
> rAlpha1 = zeros(2^m,N);
> rAlpha2 = zeros(2^m,N);
>
> for i = 1:N
> r = randi(256,1);
> rAlpha1(:,i) = rAlphaSet(r);
> r = randi(256,1);
> rAlpha2(:,i) = rAlphaSet(r);
> end
>
> Can anybody tell me why this is happening? Please, help me.
>
> Thank you very much in advance.
>
> Regards
> Galib

a hint:

% try
% ...
     rAlpha1(:,i)= rAlphaSet(:,r);
     rAlpha2(:,i)=rAlphaSet(:,r);
% ...

us

Subject: -1 / +1 problem..

From: Syed Galib

Date: 29 Jun, 2009 10:06:01

Message: 4 of 6

"us " <us@neurol.unizh.ch> wrote in message <h2a2s1$iuc$1@fred.mathworks.com>...
> "Syed Galib" <galib.cse@gmail.com> wrote in message <h2a25j$pr2$1@fred.mathworks.com>...
> > Hello all,
> >
> > I am sorry to ask you again for another problem, as I am a new MATLab user.
> >
> > I have a matrix, rAlphaSet with combinations of +1 and -1. I want to make 2 Matrices rAlpha1 and rAlpha2. I took 2 random numbers r1 and r2. Then I wanted to copy the r1th and r2th column of rAlphaSet to rAplha1 and rAlpha2. But the problem is, when I was running the code, rAlpha1 and rAlpha2 were not having the columns from rAlphaSet. Here is the code:
> >
> > rAlphaSet = (npermutek([-1 1], 2^m))';
> > rAlpha1 = zeros(2^m,N);
> > rAlpha2 = zeros(2^m,N);
> >
> > for i = 1:N
> > r = randi(256,1);
> > rAlpha1(:,i) = rAlphaSet(r);
> > r = randi(256,1);
> > rAlpha2(:,i) = rAlphaSet(r);
> > end
> >
> > Can anybody tell me why this is happening? Please, help me.
> >
> > Thank you very much in advance.
> >
> > Regards
> > Galib
>
> a hint:
>
> % try
> % ...
> rAlpha1(:,i)= rAlphaSet(:,r);
> rAlpha2(:,i)=rAlphaSet(:,r);
> % ...
>
> us

Dear Us

Thank you very much. It worked.

Thanks again.

Regards
Galib

Subject: -1 / +1 problem..

From: us

Date: 29 Jun, 2009 10:36:01

Message: 5 of 6

"Syed Galib" <galib.cse@gmail.com> wrote in message <h2a3m9$mfo$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <h2a2s1$iuc$1@fred.mathworks.com>...
> > "Syed Galib" <galib.cse@gmail.com> wrote in message <h2a25j$pr2$1@fred.mathworks.com>...
> > > Hello all,
> > >
> > > I am sorry to ask you again for another problem, as I am a new MATLab user.
> > >
> > > I have a matrix, rAlphaSet with combinations of +1 and -1. I want to make 2 Matrices rAlpha1 and rAlpha2. I took 2 random numbers r1 and r2. Then I wanted to copy the r1th and r2th column of rAlphaSet to rAplha1 and rAlpha2. But the problem is, when I was running the code, rAlpha1 and rAlpha2 were not having the columns from rAlphaSet. Here is the code:
> > >
> > > rAlphaSet = (npermutek([-1 1], 2^m))';
> > > rAlpha1 = zeros(2^m,N);
> > > rAlpha2 = zeros(2^m,N);
> > >
> > > for i = 1:N
> > > r = randi(256,1);
> > > rAlpha1(:,i) = rAlphaSet(r);
> > > r = randi(256,1);
> > > rAlpha2(:,i) = rAlphaSet(r);
> > > end
> > >
> > > Can anybody tell me why this is happening? Please, help me.
> > >
> > > Thank you very much in advance.
> > >
> > > Regards
> > > Galib
> >
> > a hint:
> >
> > % try
> > % ...
> > rAlpha1(:,i)= rAlphaSet(:,r);
> > rAlpha2(:,i)=rAlphaSet(:,r);
> > % ...
> >
> > us
>
> Dear Us
>
> Thank you very much. It worked.
>
> Thanks again.
>
> Regards
> Galib

well, so much for the syntax...
however, why not use this approach

     r=randi(256,[2,N]);
     ra1=ras(:,r(1,:));
     ra2=ras(:,r(2,:));

just a thought...
us

Subject: -1 / +1 problem..

From: Syed Galib

Date: 29 Jun, 2009 11:40:02

Message: 6 of 6

yep, this is a good approach..
actually, at first I tried not this, but something like this approach...but as the problem was ocuuring, i gave up and tried this way...but this one is a better one...

Thanks again.

Galib


"us " <us@neurol.unizh.ch> wrote in message <h2a5eh$i5b$1@fred.mathworks.com>...
> "Syed Galib" <galib.cse@gmail.com> wrote in message <h2a3m9$mfo$1@fred.mathworks.com>...
> > "us " <us@neurol.unizh.ch> wrote in message <h2a2s1$iuc$1@fred.mathworks.com>...
> > > "Syed Galib" <galib.cse@gmail.com> wrote in message <h2a25j$pr2$1@fred.mathworks.com>...
> > > > Hello all,
> > > >
> > > > I am sorry to ask you again for another problem, as I am a new MATLab user.
> > > >
> > > > I have a matrix, rAlphaSet with combinations of +1 and -1. I want to make 2 Matrices rAlpha1 and rAlpha2. I took 2 random numbers r1 and r2. Then I wanted to copy the r1th and r2th column of rAlphaSet to rAplha1 and rAlpha2. But the problem is, when I was running the code, rAlpha1 and rAlpha2 were not having the columns from rAlphaSet. Here is the code:
> > > >
> > > > rAlphaSet = (npermutek([-1 1], 2^m))';
> > > > rAlpha1 = zeros(2^m,N);
> > > > rAlpha2 = zeros(2^m,N);
> > > >
> > > > for i = 1:N
> > > > r = randi(256,1);
> > > > rAlpha1(:,i) = rAlphaSet(r);
> > > > r = randi(256,1);
> > > > rAlpha2(:,i) = rAlphaSet(r);
> > > > end
> > > >
> > > > Can anybody tell me why this is happening? Please, help me.
> > > >
> > > > Thank you very much in advance.
> > > >
> > > > Regards
> > > > Galib
> > >
> > > a hint:
> > >
> > > % try
> > > % ...
> > > rAlpha1(:,i)= rAlphaSet(:,r);
> > > rAlpha2(:,i)=rAlphaSet(:,r);
> > > % ...
> > >
> > > us
> >
> > Dear Us
> >
> > Thank you very much. It worked.
> >
> > Thanks again.
> >
> > Regards
> > Galib
>
> well, so much for the syntax...
> however, why not use this approach
>
> r=randi(256,[2,N]);
> ra1=ras(:,r(1,:));
> ra2=ras(:,r(2,:));
>
> just a thought...
> us

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us