trying to compare between matrixes

[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

Answers (2)

I don't think you are initializing 'a' properly. Try this:
a=rand(8,4);
a(a<=.5)=0;
a(a>.5)=1;
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

thank u for your answer
but what "is member" and 'rows' means in this program?
i try to take random matrix 8X4 and to search for any line 1:8 to see where to find the same line on all the 16 options of lines
like
0000=1
0001=2
0010=3
0011=4
0100=5
,
,
,
1111=16
so i need to find in my random matrix the spacific number 1:16 from all the options
thank u!
F = [0, pi/8, .....] %appropriate values for other combinations
a = rand(8,4) > 0.5;
c = pol2cart(F(1+ sum(bsxfun(@times,a,[8 4 2 1]),2)), ones(size(a,1),1));
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));
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.

Tags

Asked:

on 7 May 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!