How to sum and compare the similar elements of 3 rows????

1 回表示 (過去 30 日間)
suchismita
suchismita 2015 年 4 月 22 日
コメント済み: suchismita 2015 年 4 月 23 日
I have a 5 by 5 matrix,
A=[1 1 1 0 1;
1 0 0 0 1;
1 1 0 0 1;
1 1 0 0 0;
0 0 0 1 1]
I want to sum 3 row elements randomly and count only when all three row elements are same otherwise no,for example,
rows: {1,3,4}=2
{2,4,5}=1
{1,4,5}=0
the three rows can be any 3 out of 5, it wont be having all combinations of 3 rows.
please please help me.... and please can you explain me that how will i take 3 rows. if i will compare 4 row element then what will be the coding. please please help me.
  3 件のコメント
the cyclist
the cyclist 2015 年 4 月 22 日
Can you look at my code below, and see if that does what you want?
I feel like it might be right, but I get 3 for {1,3,4} rather than 2.
suchismita
suchismita 2015 年 4 月 23 日
image Analyst, row element means, for example,
A=rand(5,5);
b=A>0.5;
now b for example looks like
1 0 0 0 1
1 0 1 0 0
0 1 1 1 1
1 1 0 1 1
1 1 1 1 1
in b, I want to compare any 3 rows and count when all 3 rows
for example,
if i want to find for
{1,2,3}=0
{1,2,4}=1
{1,2,5}=0
{1,3,4}=...... and so on
{1,3,5}
{1,4,5}
{2,3,4}
{2,3,5}
{3,4,5}

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2015 年 4 月 22 日
編集済み: the cyclist 2015 年 4 月 22 日
A=[1 1 1 0 1;
1 0 0 0 1;
1 1 0 0 1;
1 1 0 0 0;
0 0 0 1 1];
I think I understand the rule. For the first case:
rowList = [1,3,4];
she wants to look at just rows 1,3, and 4:
A_sub = A(rowList,:)
then identify the columns where all the elements are equal:
This is the trickiest bit. First used bsxfun to see if each element is equal to its own first row. Then check to see if that is true for ALL elements in that column.
A_equal_col = all(bsxfun(@eq,A_sub,A_sub(1,:)));
Finally, count up how many columns obey the rule:
A_sum = sum(A_equal_col)
  4 件のコメント
the cyclist
the cyclist 2015 年 4 月 23 日
It's usually better to ask a new question, instead of asking a 2nd question buried in a comment where people might not see it.
But, I did happen to see this, so here you go:
nchoosek(1:5,3)
suchismita
suchismita 2015 年 4 月 23 日
thank u so much.... i will keep that in mind...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by