Changing numbers in a matrix by checking values

Dear all,
I have the following 3x50 Matrix wiht true and false values:
Ende =
0 1 0
0 0 0
0 1 0
0 0 1
1 0 1
0 0 1
1 0 1
0 0 1
1 0 1
1 1 1
0 0 1
0 1 0
0 0 0
0 0 1
0 0 1
0 1 0
1 1 0
0 1 0
0 1 0
0 0 1
0 0 0
0 0 0
1 0 1
0 0 0
1 0 1
1 0 1
1 0 1
0 1 0
0 1 0
1 0 1
0 0 0
0 0 1
1 1 1
0 1 0
0 0 1
1 1 1
0 0 1
0 1 0
0 1 0
0 0 0
0 1 0
0 1 0
0 0 0
0 0 1
0 0 1
0 0 1
1 0 1
0 0 1
0 0 0
0 1 0
In every line with 1 1 0 or 1 1 1: If in column 3 the value is 0 than I need to change the value in column 2 into 0 --> I want to make in the matrix out of 1 1 0 , a new updated line 0 1 0. Same for 1 1 1 --> I want to change those lines into 1 0 1.
Is anyone around who could help on this?
Cheers, Felix

1 件のコメント

Jan
Jan 2017 年 5 月 21 日
change the value in column 2 into 0 --> I want to make in the
matrix out of 1 1 0 , a new updated line 0 1 0
This changes the first column, not the second one.

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

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2017 年 5 月 20 日
編集済み: Andrei Bobrov 2017 年 5 月 20 日

0 投票

[EDIT]
a = [0 1 0;1 0 1];
[l0,ii] = ismember(Ende,[1 1 0;1 1 1],'rows');
Ende(l0,:) = a(ii(l0),:);

2 件のコメント

Felix_2991
Felix_2991 2017 年 5 月 20 日
Thanks for the quick response, I copied the code, but I got not the result i hoped to get, the matrix is not changing :/
Andrei Bobrov
Andrei Bobrov 2017 年 5 月 20 日
I'm fixed.

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

Jan
Jan 2017 年 5 月 21 日

0 投票

In Matlab >= R2016a:
index = (Ende == [1 1 0]);
Ende(index, 1) = 0;
index = (Ende == [1 1 1]);
Ende(index, 2) = 0;

カテゴリ

製品

質問済み:

2017 年 5 月 20 日

回答済み:

Jan
2017 年 5 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by