Thread Subject: random letter generator

Subject: random letter generator

From: Al B

Date: 17 Jan, 2009 15:39:01

Message: 1 of 15

Hi,

I was wondering if anybody knows how to implement a random letter generator..

Thanks,

Subject: random letter generator

From: Sadik

Date: 17 Jan, 2009 16:22:02

Message: 2 of 15

"Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> Hi,
>
> I was wondering if anybody knows how to implement a random letter generator..
>
> Thanks,

Hello Al,

If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.

There is a built in function about this:

out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.

Hope this helps.

Subject: random letter generator

From: John D'Errico

Date: 17 Jan, 2009 16:29:01

Message: 3 of 15

"Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> Hi,
>
> I was wondering if anybody knows how to implement a random letter generator..
>

Can you generate random integers between 1
and 26?

If so, then can you generate random letters?
How might you do this? There are at least several
ways.

char((1:26)+64)

John

Subject: random letter generator

From: Al Ramo

Date: 17 Jan, 2009 16:47:01

Message: 4 of 15

Thanks !

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gkt10d$it8$1@fred.mathworks.com>...
> "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > Hi,
> >
> > I was wondering if anybody knows how to implement a random letter generator..
> >
>
> Can you generate random integers between 1
> and 26?
>
> If so, then can you generate random letters?
> How might you do this? There are at least several
> ways.
>
> char((1:26)+64)
>
> John

Subject: random letter generator

From: Al Ramo

Date: 17 Jan, 2009 17:51:02

Message: 5 of 15

Thanks Sadik,,

I actually created the following alphebet vector from a string:

str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
[alphabet] = strread(str, '%s' , 'delimiter', ', ');

however, when I use: out = randsrc(m,n,alphabet), I get the following
error : Only numeric arguments are accepted

which is weird, because I assume that randsrc also works for characters.

Your help in this is appreciated.. Thanks


"Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > Hi,
> >
> > I was wondering if anybody knows how to implement a random letter generator..
> >
> > Thanks,
>
> Hello Al,
>
> If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
>
> There is a built in function about this:
>
> out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
>
> Hope this helps.

Subject: random letter generator

From: Sadik

Date: 17 Jan, 2009 20:50:03

Message: 6 of 15

How about this

str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
[alphabet] = strread(str, '%s' , 'delimiter', ', ');
out = alphabet{randsrc(m,n,1:length(alphabet))};

"Al Ramo" <shal.hat@gmail.com> wrote in message <gkt5q6$ro8$1@fred.mathworks.com>...
> Thanks Sadik,,
>
> I actually created the following alphebet vector from a string:
>
> str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> [alphabet] = strread(str, '%s' , 'delimiter', ', ');
>
> however, when I use: out = randsrc(m,n,alphabet), I get the following
> error : Only numeric arguments are accepted
>
> which is weird, because I assume that randsrc also works for characters.
>
> Your help in this is appreciated.. Thanks
>
>
> "Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> > "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > I was wondering if anybody knows how to implement a random letter generator..
> > >
> > > Thanks,
> >
> > Hello Al,
> >
> > If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
> >
> > There is a built in function about this:
> >
> > out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
> >
> > Hope this helps.

Subject: random letter generator

From: Al Ramo

Date: 17 Jan, 2009 21:06:02

Message: 7 of 15

error: Illegal right hand side in assignment. Too many elements.


"Sadik " <sadik.hava@gmail.com> wrote in message <gktg9r$78n$1@fred.mathworks.com>...
> How about this
>
> str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> out = alphabet{randsrc(m,n,1:length(alphabet))};
>
> "Al Ramo" <shal.hat@gmail.com> wrote in message <gkt5q6$ro8$1@fred.mathworks.com>...
> > Thanks Sadik,,
> >
> > I actually created the following alphebet vector from a string:
> >
> > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> >
> > however, when I use: out = randsrc(m,n,alphabet), I get the following
> > error : Only numeric arguments are accepted
> >
> > which is weird, because I assume that randsrc also works for characters.
> >
> > Your help in this is appreciated.. Thanks
> >
> >
> > "Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> > > "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > > > Hi,
> > > >
> > > > I was wondering if anybody knows how to implement a random letter generator..
> > > >
> > > > Thanks,
> > >
> > > Hello Al,
> > >
> > > If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
> > >
> > > There is a built in function about this:
> > >
> > > out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
> > >
> > > Hope this helps.

Subject: random letter generator

From: Sadik

Date: 17 Jan, 2009 21:23:01

Message: 8 of 15

It works on my computer with MATLAB 7. The problem should be the 1:length part.

Then,
str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
[alphabet] = strread(str, '%s' , 'delimiter', ', ');
out = alphabet{randsrc(m,n,(1:length(alphabet)))};

or, even better,

str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
[alphabet] = strread(str, '%s' , 'delimiter', ', ');
out = alphabet{randint(m,n,[1 length(alphabet)])};

Please let know if it works.

"Al Ramo" <shal.hat@gmail.com> wrote in message <gkth7q$7bd$1@fred.mathworks.com>...
> error: Illegal right hand side in assignment. Too many elements.
>
>
> "Sadik " <sadik.hava@gmail.com> wrote in message <gktg9r$78n$1@fred.mathworks.com>...
> > How about this
> >
> > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > out = alphabet{randsrc(m,n,1:length(alphabet))};
> >
> > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkt5q6$ro8$1@fred.mathworks.com>...
> > > Thanks Sadik,,
> > >
> > > I actually created the following alphebet vector from a string:
> > >
> > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > >
> > > however, when I use: out = randsrc(m,n,alphabet), I get the following
> > > error : Only numeric arguments are accepted
> > >
> > > which is weird, because I assume that randsrc also works for characters.
> > >
> > > Your help in this is appreciated.. Thanks
> > >
> > >
> > > "Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> > > > "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > > > > Hi,
> > > > >
> > > > > I was wondering if anybody knows how to implement a random letter generator..
> > > > >
> > > > > Thanks,
> > > >
> > > > Hello Al,
> > > >
> > > > If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
> > > >
> > > > There is a built in function about this:
> > > >
> > > > out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
> > > >
> > > > Hope this helps.

Subject: random letter generator

From: Al Ramo

Date: 17 Jan, 2009 22:38:01

Message: 9 of 15

unfortunately I still get the same error for both codes..

Your help in this is greatly appreciated..

"Sadik " <sadik.hava@gmail.com> wrote in message <gkti7l$b9d$1@fred.mathworks.com>...
> It works on my computer with MATLAB 7. The problem should be the 1:length part.
>
> Then,
> str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> out = alphabet{randsrc(m,n,(1:length(alphabet)))};
>
> or, even better,
>
> str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> out = alphabet{randint(m,n,[1 length(alphabet)])};
>
> Please let know if it works.
>
> "Al Ramo" <shal.hat@gmail.com> wrote in message <gkth7q$7bd$1@fred.mathworks.com>...
> > error: Illegal right hand side in assignment. Too many elements.
> >
> >
> > "Sadik " <sadik.hava@gmail.com> wrote in message <gktg9r$78n$1@fred.mathworks.com>...
> > > How about this
> > >
> > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > out = alphabet{randsrc(m,n,1:length(alphabet))};
> > >
> > > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkt5q6$ro8$1@fred.mathworks.com>...
> > > > Thanks Sadik,,
> > > >
> > > > I actually created the following alphebet vector from a string:
> > > >
> > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > >
> > > > however, when I use: out = randsrc(m,n,alphabet), I get the following
> > > > error : Only numeric arguments are accepted
> > > >
> > > > which is weird, because I assume that randsrc also works for characters.
> > > >
> > > > Your help in this is appreciated.. Thanks
> > > >
> > > >
> > > > "Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> > > > > "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > > > > > Hi,
> > > > > >
> > > > > > I was wondering if anybody knows how to implement a random letter generator..
> > > > > >
> > > > > > Thanks,
> > > > >
> > > > > Hello Al,
> > > > >
> > > > > If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
> > > > >
> > > > > There is a built in function about this:
> > > > >
> > > > > out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
> > > > >
> > > > > Hope this helps.

Subject: random letter generator

From: Al Ramo

Date: 17 Jan, 2009 22:51:01

Message: 10 of 15

Works now ! debugged it : I used ( instead of {

Thanks again for your help !
since you were very helpful in this part, I was wondering if you could
help me with the following :

I have a 220 x 108 data matrix

I have generated a 108 x 10 matrix of random letters a:c ,
so each cell in this matrix is either (in this case) a a , b, or c.

Now I want to take first column of the 108 x 10 matrix, and assign the number
in the first cell of that column as the 'name' of the first column in the 220 x 108,
and assign the number in the second cell of the same column as the 'name' to
the second column in the 220 x 108 matrix, and assign the number in the third
cell of the same column as the 'name' to the third column in the 220 x 108 matrix,
and so on... Therefore when I call for example a "b" this will give me all the columns
in the 220 x 108 matrix that were labeled by a "b". Then I want to save this as a new data matrix...
Then I want to do this for all the columns in the 108 x 10 matrix.

Thanks again Sadik
"Sadik " <sadik.hava@gmail.com> wrote in message <gkti7l$b9d$1@fred.mathworks.com>...
> It works on my computer with MATLAB 7. The problem should be the 1:length part.
>
> Then,
> str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> out = alphabet{randsrc(m,n,(1:length(alphabet)))};
>
> or, even better,
>
> str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> out = alphabet{randint(m,n,[1 length(alphabet)])};
>
> Please let know if it works.
>
> "Al Ramo" <shal.hat@gmail.com> wrote in message <gkth7q$7bd$1@fred.mathworks.com>...
> > error: Illegal right hand side in assignment. Too many elements.
> >
> >
> > "Sadik " <sadik.hava@gmail.com> wrote in message <gktg9r$78n$1@fred.mathworks.com>...
> > > How about this
> > >
> > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > out = alphabet{randsrc(m,n,1:length(alphabet))};
> > >
> > > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkt5q6$ro8$1@fred.mathworks.com>...
> > > > Thanks Sadik,,
> > > >
> > > > I actually created the following alphebet vector from a string:
> > > >
> > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > >
> > > > however, when I use: out = randsrc(m,n,alphabet), I get the following
> > > > error : Only numeric arguments are accepted
> > > >
> > > > which is weird, because I assume that randsrc also works for characters.
> > > >
> > > > Your help in this is appreciated.. Thanks
> > > >
> > > >
> > > > "Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> > > > > "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > > > > > Hi,
> > > > > >
> > > > > > I was wondering if anybody knows how to implement a random letter generator..
> > > > > >
> > > > > > Thanks,
> > > > >
> > > > > Hello Al,
> > > > >
> > > > > If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
> > > > >
> > > > > There is a built in function about this:
> > > > >
> > > > > out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
> > > > >
> > > > > Hope this helps.

Subject: random letter generator

From: Sadik

Date: 18 Jan, 2009 00:47:01

Message: 11 of 15

Hello Al,

I had always set m = n = 1, and it of course worked that way. I hadn't tried for other m and n. Sorry for that. Yes, () instead of {} solves the problem.

I believe you can do this as follows:

After you have the 108x10 matrix, in the first column, there are 'a's, 'b's and 'c's. Now, let us try to find 'a's in the first column of the variable out formed by your previous code:

firstColumn = [out{:,1}]; %This gives a row string, concatenation of all the %elements in the first row
aLocations = find(firstColumn=='a');

%Let us call the 220x108 data matrix as dataMatrix.

all_aData = dataMatrix(:,aLocations); %This is the new data matrix formed by all the % columns labeled by 'a'.

So if you would like to do this for all 10 columns of the labels:

%We will keep all of the new data matrices in a cell called allNewData. It will be %10x3 and each cell will contain the new data matrices classified by labels:

allNewData = cell(10,3);

for labelColumn = 1:10
     currentColumn = [out{:,labelColumn}];
     aLocations = find(currentColumn=='a');
     bLocations = find(currentColumn=='b');
     cLocations = find(currentColumn=='c');
     allNewData{labelColumn,1} = dataMatrix(:,aLocations);
     allNewData{labelColumn,2} = dataMatrix(:,bLocations);
     allNewData{labelColumn,3} = dataMatrix(:,cLocations);
end

It seems to work. Please let know if it works for you as well.

"Al Ramo" <shal.hat@gmail.com> wrote in message <gktncl$a3f$1@fred.mathworks.com>...
> Works now ! debugged it : I used ( instead of {
>
> Thanks again for your help !
> since you were very helpful in this part, I was wondering if you could
> help me with the following :
>
> I have a 220 x 108 data matrix
>
> I have generated a 108 x 10 matrix of random letters a:c ,
> so each cell in this matrix is either (in this case) a a , b, or c.
>
> Now I want to take first column of the 108 x 10 matrix, and assign the number
> in the first cell of that column as the 'name' of the first column in the 220 x 108,
> and assign the number in the second cell of the same column as the 'name' to
> the second column in the 220 x 108 matrix, and assign the number in the third
> cell of the same column as the 'name' to the third column in the 220 x 108 matrix,
> and so on... Therefore when I call for example a "b" this will give me all the columns
> in the 220 x 108 matrix that were labeled by a "b". Then I want to save this as a new data matrix...
> Then I want to do this for all the columns in the 108 x 10 matrix.
>
> Thanks again Sadik
> "Sadik " <sadik.hava@gmail.com> wrote in message <gkti7l$b9d$1@fred.mathworks.com>...
> > It works on my computer with MATLAB 7. The problem should be the 1:length part.
> >
> > Then,
> > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > out = alphabet{randsrc(m,n,(1:length(alphabet)))};
> >
> > or, even better,
> >
> > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > out = alphabet{randint(m,n,[1 length(alphabet)])};
> >
> > Please let know if it works.
> >
> > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkth7q$7bd$1@fred.mathworks.com>...
> > > error: Illegal right hand side in assignment. Too many elements.
> > >
> > >
> > > "Sadik " <sadik.hava@gmail.com> wrote in message <gktg9r$78n$1@fred.mathworks.com>...
> > > > How about this
> > > >
> > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > out = alphabet{randsrc(m,n,1:length(alphabet))};
> > > >
> > > > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkt5q6$ro8$1@fred.mathworks.com>...
> > > > > Thanks Sadik,,
> > > > >
> > > > > I actually created the following alphebet vector from a string:
> > > > >
> > > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > >
> > > > > however, when I use: out = randsrc(m,n,alphabet), I get the following
> > > > > error : Only numeric arguments are accepted
> > > > >
> > > > > which is weird, because I assume that randsrc also works for characters.
> > > > >
> > > > > Your help in this is appreciated.. Thanks
> > > > >
> > > > >
> > > > > "Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> > > > > > "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > > > > > > Hi,
> > > > > > >
> > > > > > > I was wondering if anybody knows how to implement a random letter generator..
> > > > > > >
> > > > > > > Thanks,
> > > > > >
> > > > > > Hello Al,
> > > > > >
> > > > > > If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
> > > > > >
> > > > > > There is a built in function about this:
> > > > > >
> > > > > > out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
> > > > > >
> > > > > > Hope this helps.

Subject: random letter generator

From: Al Ramo

Date: 18 Jan, 2009 14:52:01

Message: 12 of 15

Thanks Sadik.. You have been of great help.. do you mind if I could
consult with you later about other things?

"Sadik " <sadik.hava@gmail.com> wrote in message <gktu65$74u$1@fred.mathworks.com>...
> Hello Al,
>
> I had always set m = n = 1, and it of course worked that way. I hadn't tried for other m and n. Sorry for that. Yes, () instead of {} solves the problem.
>
> I believe you can do this as follows:
>
> After you have the 108x10 matrix, in the first column, there are 'a's, 'b's and 'c's. Now, let us try to find 'a's in the first column of the variable out formed by your previous code:
>
> firstColumn = [out{:,1}]; %This gives a row string, concatenation of all the %elements in the first row
> aLocations = find(firstColumn=='a');
>
> %Let us call the 220x108 data matrix as dataMatrix.
>
> all_aData = dataMatrix(:,aLocations); %This is the new data matrix formed by all the % columns labeled by 'a'.
>
> So if you would like to do this for all 10 columns of the labels:
>
> %We will keep all of the new data matrices in a cell called allNewData. It will be %10x3 and each cell will contain the new data matrices classified by labels:
>
> allNewData = cell(10,3);
>
> for labelColumn = 1:10
> currentColumn = [out{:,labelColumn}];
> aLocations = find(currentColumn=='a');
> bLocations = find(currentColumn=='b');
> cLocations = find(currentColumn=='c');
> allNewData{labelColumn,1} = dataMatrix(:,aLocations);
> allNewData{labelColumn,2} = dataMatrix(:,bLocations);
> allNewData{labelColumn,3} = dataMatrix(:,cLocations);
> end
>
> It seems to work. Please let know if it works for you as well.
>
> "Al Ramo" <shal.hat@gmail.com> wrote in message <gktncl$a3f$1@fred.mathworks.com>...
> > Works now ! debugged it : I used ( instead of {
> >
> > Thanks again for your help !
> > since you were very helpful in this part, I was wondering if you could
> > help me with the following :
> >
> > I have a 220 x 108 data matrix
> >
> > I have generated a 108 x 10 matrix of random letters a:c ,
> > so each cell in this matrix is either (in this case) a a , b, or c.
> >
> > Now I want to take first column of the 108 x 10 matrix, and assign the number
> > in the first cell of that column as the 'name' of the first column in the 220 x 108,
> > and assign the number in the second cell of the same column as the 'name' to
> > the second column in the 220 x 108 matrix, and assign the number in the third
> > cell of the same column as the 'name' to the third column in the 220 x 108 matrix,
> > and so on... Therefore when I call for example a "b" this will give me all the columns
> > in the 220 x 108 matrix that were labeled by a "b". Then I want to save this as a new data matrix...
> > Then I want to do this for all the columns in the 108 x 10 matrix.
> >
> > Thanks again Sadik
> > "Sadik " <sadik.hava@gmail.com> wrote in message <gkti7l$b9d$1@fred.mathworks.com>...
> > > It works on my computer with MATLAB 7. The problem should be the 1:length part.
> > >
> > > Then,
> > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > out = alphabet{randsrc(m,n,(1:length(alphabet)))};
> > >
> > > or, even better,
> > >
> > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > out = alphabet{randint(m,n,[1 length(alphabet)])};
> > >
> > > Please let know if it works.
> > >
> > > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkth7q$7bd$1@fred.mathworks.com>...
> > > > error: Illegal right hand side in assignment. Too many elements.
> > > >
> > > >
> > > > "Sadik " <sadik.hava@gmail.com> wrote in message <gktg9r$78n$1@fred.mathworks.com>...
> > > > > How about this
> > > > >
> > > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > > out = alphabet{randsrc(m,n,1:length(alphabet))};
> > > > >
> > > > > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkt5q6$ro8$1@fred.mathworks.com>...
> > > > > > Thanks Sadik,,
> > > > > >
> > > > > > I actually created the following alphebet vector from a string:
> > > > > >
> > > > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > > >
> > > > > > however, when I use: out = randsrc(m,n,alphabet), I get the following
> > > > > > error : Only numeric arguments are accepted
> > > > > >
> > > > > > which is weird, because I assume that randsrc also works for characters.
> > > > > >
> > > > > > Your help in this is appreciated.. Thanks
> > > > > >
> > > > > >
> > > > > > "Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> > > > > > > "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I was wondering if anybody knows how to implement a random letter generator..
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > >
> > > > > > > Hello Al,
> > > > > > >
> > > > > > > If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
> > > > > > >
> > > > > > > There is a built in function about this:
> > > > > > >
> > > > > > > out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
> > > > > > >
> > > > > > > Hope this helps.

Subject: random letter generator

From: Sadik

Date: 18 Jan, 2009 15:07:01

Message: 13 of 15

Definitely!

"Al Ramo" <shal.hat@gmail.com> wrote in message <gkvfmh$7s5$1@fred.mathworks.com>...
> Thanks Sadik.. You have been of great help.. do you mind if I could
> consult with you later about other things?
>
> "Sadik " <sadik.hava@gmail.com> wrote in message <gktu65$74u$1@fred.mathworks.com>...
> > Hello Al,
> >
> > I had always set m = n = 1, and it of course worked that way. I hadn't tried for other m and n. Sorry for that. Yes, () instead of {} solves the problem.
> >
> > I believe you can do this as follows:
> >
> > After you have the 108x10 matrix, in the first column, there are 'a's, 'b's and 'c's. Now, let us try to find 'a's in the first column of the variable out formed by your previous code:
> >
> > firstColumn = [out{:,1}]; %This gives a row string, concatenation of all the %elements in the first row
> > aLocations = find(firstColumn=='a');
> >
> > %Let us call the 220x108 data matrix as dataMatrix.
> >
> > all_aData = dataMatrix(:,aLocations); %This is the new data matrix formed by all the % columns labeled by 'a'.
> >
> > So if you would like to do this for all 10 columns of the labels:
> >
> > %We will keep all of the new data matrices in a cell called allNewData. It will be %10x3 and each cell will contain the new data matrices classified by labels:
> >
> > allNewData = cell(10,3);
> >
> > for labelColumn = 1:10
> > currentColumn = [out{:,labelColumn}];
> > aLocations = find(currentColumn=='a');
> > bLocations = find(currentColumn=='b');
> > cLocations = find(currentColumn=='c');
> > allNewData{labelColumn,1} = dataMatrix(:,aLocations);
> > allNewData{labelColumn,2} = dataMatrix(:,bLocations);
> > allNewData{labelColumn,3} = dataMatrix(:,cLocations);
> > end
> >
> > It seems to work. Please let know if it works for you as well.
> >
> > "Al Ramo" <shal.hat@gmail.com> wrote in message <gktncl$a3f$1@fred.mathworks.com>...
> > > Works now ! debugged it : I used ( instead of {
> > >
> > > Thanks again for your help !
> > > since you were very helpful in this part, I was wondering if you could
> > > help me with the following :
> > >
> > > I have a 220 x 108 data matrix
> > >
> > > I have generated a 108 x 10 matrix of random letters a:c ,
> > > so each cell in this matrix is either (in this case) a a , b, or c.
> > >
> > > Now I want to take first column of the 108 x 10 matrix, and assign the number
> > > in the first cell of that column as the 'name' of the first column in the 220 x 108,
> > > and assign the number in the second cell of the same column as the 'name' to
> > > the second column in the 220 x 108 matrix, and assign the number in the third
> > > cell of the same column as the 'name' to the third column in the 220 x 108 matrix,
> > > and so on... Therefore when I call for example a "b" this will give me all the columns
> > > in the 220 x 108 matrix that were labeled by a "b". Then I want to save this as a new data matrix...
> > > Then I want to do this for all the columns in the 108 x 10 matrix.
> > >
> > > Thanks again Sadik
> > > "Sadik " <sadik.hava@gmail.com> wrote in message <gkti7l$b9d$1@fred.mathworks.com>...
> > > > It works on my computer with MATLAB 7. The problem should be the 1:length part.
> > > >
> > > > Then,
> > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > out = alphabet{randsrc(m,n,(1:length(alphabet)))};
> > > >
> > > > or, even better,
> > > >
> > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > out = alphabet{randint(m,n,[1 length(alphabet)])};
> > > >
> > > > Please let know if it works.
> > > >
> > > > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkth7q$7bd$1@fred.mathworks.com>...
> > > > > error: Illegal right hand side in assignment. Too many elements.
> > > > >
> > > > >
> > > > > "Sadik " <sadik.hava@gmail.com> wrote in message <gktg9r$78n$1@fred.mathworks.com>...
> > > > > > How about this
> > > > > >
> > > > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > > > out = alphabet{randsrc(m,n,1:length(alphabet))};
> > > > > >
> > > > > > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkt5q6$ro8$1@fred.mathworks.com>...
> > > > > > > Thanks Sadik,,
> > > > > > >
> > > > > > > I actually created the following alphebet vector from a string:
> > > > > > >
> > > > > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > > > >
> > > > > > > however, when I use: out = randsrc(m,n,alphabet), I get the following
> > > > > > > error : Only numeric arguments are accepted
> > > > > > >
> > > > > > > which is weird, because I assume that randsrc also works for characters.
> > > > > > >
> > > > > > > Your help in this is appreciated.. Thanks
> > > > > > >
> > > > > > >
> > > > > > > "Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> > > > > > > > "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > > > > > > > > Hi,
> > > > > > > > >
> > > > > > > > > I was wondering if anybody knows how to implement a random letter generator..
> > > > > > > > >
> > > > > > > > > Thanks,
> > > > > > > >
> > > > > > > > Hello Al,
> > > > > > > >
> > > > > > > > If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
> > > > > > > >
> > > > > > > > There is a built in function about this:
> > > > > > > >
> > > > > > > > out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
> > > > > > > >
> > > > > > > > Hope this helps.

Subject: random letter generator

From: Al Ramo

Date: 18 Jan, 2009 16:25:03

Message: 14 of 15

Thanks Sadik.. You have been of great help.. do you mind if I could
consult with you later about other things?

"Sadik " <sadik.hava@gmail.com> wrote in message <gktu65$74u$1@fred.mathworks.com>...
> Hello Al,
>
> I had always set m = n = 1, and it of course worked that way. I hadn't tried for other m and n. Sorry for that. Yes, () instead of {} solves the problem.
>
> I believe you can do this as follows:
>
> After you have the 108x10 matrix, in the first column, there are 'a's, 'b's and 'c's. Now, let us try to find 'a's in the first column of the variable out formed by your previous code:
>
> firstColumn = [out{:,1}]; %This gives a row string, concatenation of all the %elements in the first row
> aLocations = find(firstColumn=='a');
>
> %Let us call the 220x108 data matrix as dataMatrix.
>
> all_aData = dataMatrix(:,aLocations); %This is the new data matrix formed by all the % columns labeled by 'a'.
>
> So if you would like to do this for all 10 columns of the labels:
>
> %We will keep all of the new data matrices in a cell called allNewData. It will be %10x3 and each cell will contain the new data matrices classified by labels:
>
> allNewData = cell(10,3);
>
> for labelColumn = 1:10
> currentColumn = [out{:,labelColumn}];
> aLocations = find(currentColumn=='a');
> bLocations = find(currentColumn=='b');
> cLocations = find(currentColumn=='c');
> allNewData{labelColumn,1} = dataMatrix(:,aLocations);
> allNewData{labelColumn,2} = dataMatrix(:,bLocations);
> allNewData{labelColumn,3} = dataMatrix(:,cLocations);
> end
>
> It seems to work. Please let know if it works for you as well.
>
> "Al Ramo" <shal.hat@gmail.com> wrote in message <gktncl$a3f$1@fred.mathworks.com>...
> > Works now ! debugged it : I used ( instead of {
> >
> > Thanks again for your help !
> > since you were very helpful in this part, I was wondering if you could
> > help me with the following :
> >
> > I have a 220 x 108 data matrix
> >
> > I have generated a 108 x 10 matrix of random letters a:c ,
> > so each cell in this matrix is either (in this case) a a , b, or c.
> >
> > Now I want to take first column of the 108 x 10 matrix, and assign the number
> > in the first cell of that column as the 'name' of the first column in the 220 x 108,
> > and assign the number in the second cell of the same column as the 'name' to
> > the second column in the 220 x 108 matrix, and assign the number in the third
> > cell of the same column as the 'name' to the third column in the 220 x 108 matrix,
> > and so on... Therefore when I call for example a "b" this will give me all the columns
> > in the 220 x 108 matrix that were labeled by a "b". Then I want to save this as a new data matrix...
> > Then I want to do this for all the columns in the 108 x 10 matrix.
> >
> > Thanks again Sadik
> > "Sadik " <sadik.hava@gmail.com> wrote in message <gkti7l$b9d$1@fred.mathworks.com>...
> > > It works on my computer with MATLAB 7. The problem should be the 1:length part.
> > >
> > > Then,
> > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > out = alphabet{randsrc(m,n,(1:length(alphabet)))};
> > >
> > > or, even better,
> > >
> > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > out = alphabet{randint(m,n,[1 length(alphabet)])};
> > >
> > > Please let know if it works.
> > >
> > > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkth7q$7bd$1@fred.mathworks.com>...
> > > > error: Illegal right hand side in assignment. Too many elements.
> > > >
> > > >
> > > > "Sadik " <sadik.hava@gmail.com> wrote in message <gktg9r$78n$1@fred.mathworks.com>...
> > > > > How about this
> > > > >
> > > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > > out = alphabet{randsrc(m,n,1:length(alphabet))};
> > > > >
> > > > > "Al Ramo" <shal.hat@gmail.com> wrote in message <gkt5q6$ro8$1@fred.mathworks.com>...
> > > > > > Thanks Sadik,,
> > > > > >
> > > > > > I actually created the following alphebet vector from a string:
> > > > > >
> > > > > > str = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee';
> > > > > > [alphabet] = strread(str, '%s' , 'delimiter', ', ');
> > > > > >
> > > > > > however, when I use: out = randsrc(m,n,alphabet), I get the following
> > > > > > error : Only numeric arguments are accepted
> > > > > >
> > > > > > which is weird, because I assume that randsrc also works for characters.
> > > > > >
> > > > > > Your help in this is appreciated.. Thanks
> > > > > >
> > > > > >
> > > > > > "Sadik " <sadik.hava@gmail.com> wrote in message <gkt0ja$mck$1@fred.mathworks.com>...
> > > > > > > "Al B" <bourisly@gmail.com> wrote in message <gksu2l$9g0$1@fred.mathworks.com>...
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I was wondering if anybody knows how to implement a random letter generator..
> > > > > > > >
> > > > > > > > Thanks,
> > > > > > >
> > > > > > > Hello Al,
> > > > > > >
> > > > > > > If it is not too simple a logical way, you could form a 26-character vector, then randomly draw a letter from this vector.
> > > > > > >
> > > > > > > There is a built in function about this:
> > > > > > >
> > > > > > > out = randsrc(m,n,alphabet) generates an m-by-n matrix, each of whose entries is independently chosen from the entries in the row vector alphabet. Each entry in alphabet occurs in out with equal probability. Duplicate values in alphabet are ignored.
> > > > > > >
> > > > > > > Hope this helps.

Subject: random letter generator

From: Sadik

Date: 18 Jan, 2009 17:20:03

Message: 15 of 15

Yes, sure.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
rand Al Ramo 17 Jan, 2009 10:40:20
random Al Ramo 17 Jan, 2009 10:40:20
letter Al Ramo 17 Jan, 2009 10:40:20
word Al Ramo 17 Jan, 2009 10:40:20
generator Al Ramo 17 Jan, 2009 10:40:20
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com