|
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.
|