Info
This question is closed. Reopen it to edit or answer.
trying to compare between matrixes
1 view (last 30 days)
Show older comments
[EDIT: 20110512 23:42 CDT - incorporate duplicate post - WDR]
hello!!!
I'm trying to compare between 2 matrices the first matrix is 8X4 so there is 8 users that gets a random variables '0' or '1' so I'm trying to compare all the lines to the maximum combinations (2^4)
this is part of my program but its doesn't running i would like to read yours comments about it and maybe someone can help me to solve this problem
thank u very much!
this is the program (i wrote only 2 lines of the compare but i might sure u understand the idea... :D ) and as u can see if the compare is right then C will get some number if not it will jump to the other line
clear all
for i=1:4 %data
for q=1:8 %users
a=rand(q,i)
if (a(i) <=0.5)
b(q,i)=0
else
if( a(i) >0.5)
b(q,i)=1
end
end
end
end
for q=1:8
if b(q,1:4)~={[0,0,0,1]|[0,0,1,0]|[0,0,1,1]|[0,1,0,0]|[0,1,0,1]|[0,1,1,0]|[0,1,1,1]|[1,0,0,0]|[1,0,0,1]|[1,0,1,0]|[1,0,1,1]
[1,1,0,0]|[1,1,0,1]|[1,1,1,0]|[1,1,1,1]}
c=pol2cart(0,1)
else
if b(q,1:4)~={[0,0,0,0]|[0,0,1,0]|[0,0,1,1]|[0,1,0,0]|[0,1,0,1]|[0,1,1,0]|[0,1,1,1]|[1,0,0,0]|[1,0,0,1]|[1,0,1,0]|[1,0,1,1]
[1,1,0,0]|[1,1,0,1]|[1,1,1,0]|[1,1,1,1]}
c=pol2cart(pi/8,1)
EDITOR: the duplicate post expanded the "if" cascade to:
for q=1:8
if b(q,1:4)~={[0,0,0,1]|[0,0,1,0]|[0,0,1,1]|[0,1,0,0]|[0,1,0,1]|[0,1,1,0]|[0,1,1,1]|[1,0,0,0]|[1,0,0,1]|[1,0,1,0]|[1,0,1,1]
[1,1,0,0]|[1,1,0,1]|[1,1,1,0]|[1,1,1,1]}
c=pol2cart(0,1)
else
if b(q,1:4)~={[0,0,0,0]|[0,0,1,0]|[0,0,1,1]|[0,1,0,0]|[0,1,0,1]|[0,1,1,0]|[0,1,1,1]|[1,0,0,0]|[1,0,0,1]|[1,0,1,0]|[1,0,1,1]
[1,1,0,0]|[1,1,0,1]|[1,1,1,0]|[1,1,1,1]}
c=pol2cart(pi/8,1)
else
if b(q,1:4)~={[0,0,0,1]|[0,0,0,0]|[0,0,1,1]|[0,1,0,0]|[0,1,0,1]|[0,1,1,0]|[0,1,1,1]|[1,0,0,0]|[1,0,0,1]|[1,0,1,0]|[1,0,1,1]
[1,1,0,0]|[1,1,0,1]|[1,1,1,0]|[1,1,1,1]}
c=pol2cart(2*pi/8,1)
else
if b(q,1:4)~={[0,0,0,1]|[0,0,1,0]|[0,0,0,0]|[0,1,0,0]|[0,1,0,1]|[0,1,1,0]|[0,1,1,1]|[1,0,0,0]|[1,0,0,1]|[1,0,1,0]|[1,0,1,1]
[1,1,0,0]|[1,1,0,1]|[1,1,1,0]|[1,1,1,1]}
c=pol2cart(3*pi/8,1)
else.
.
.
.
.
.
[1,1,0,0]|[1,1,0,1]|[0,0,0,0]|[1,1,1,1]}
c=pol2cart(14*pi/8,1)
else
if b(q,1:4)~={[0,0,0,1]|[0,0,1,0]|[0,0,1,1]|[0,1,0,0]|[0,1,0,1]|[0,1,1,0]|[0,1,1,1]|[1,0,0,0]|[1,0,0,1]|[1,0,1,0]|[1,0,1,1]
[1,1,0,0]|[1,1,0,1]|[1,1,1,0]|[0,0,0,0]}
c=pol2cart(15*pi/8,1)
end
end
end
0 Comments
Answers (2)
bym
on 7 May 2011
I don't think you are initializing 'a' properly. Try this:
a=rand(8,4);
a(a<=.5)=0;
a(a>.5)=1;
0 Comments
Walter Roberson
on 7 May 2011
Comparing a numeric array to a cell array will give you an error. You need something like,
if ismember(b(q,1:4), [0,0,0,1;0,0,1,0;0,0,1,1;0,1,0,0;0,1,0,1;0,1,1,0;0,1,1,1;1,0,0,0;1,0,0,1;1,0,1,0;1,0,1,1;1,1,0,0;1,1,0,1;1,1,1,0;1,1,1,1], 'rows')
4 Comments
Walter Roberson
on 8 May 2011
Looking at your other post for the values you wish to use, the code reduces to
a = rand(8,4) > 0.5;
c = pol2cart(Pi/8 * sum(bsxfun(@times,a,[8 4 2 1]),2), ones(size(a,1),1));
Walter Roberson
on 8 May 2011
As to what ismember() and rows means in context, here is the link to the documentation: http://www.mathworks.com/help/techdoc/ref/ismember.html
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!