Substituting values in a matrix

2 ビュー (過去 30 日間)
med-sweng
med-sweng 2013 年 2 月 23 日
Say I have the following two matrices:
>> x = [1 4 3; 6 4 3; 6 9 3; 2 4 3; 5 4 0; 5 3 1; 6 4 7];
>> y = [0 0 1; 1 1 0; 1 1 0; 0 1 1; 0.2 0.8 0.54; 1 1 1; 0 0 0];
Where you can think of `x` as some image, and `y` the *degree of membership* of of each element of `x` to some region of interest.
Say I set those elements in `x` that have degree of membership = 1 to `1` and the other elements to `0` as follows:
x = zeros(size(y));
x(y==1) = 1;
In which case I will have the following output:
0 0 1
1 1 0
1 1 0
0 1 1
0 0 0
1 1 1
0 0 0
Now, for the elements of `0`, how can I substitute their values with the value of `y` in the corresponding location?
Thanks.

採用された回答

Walter Roberson
Walter Roberson 2013 年 2 月 23 日
x(x==0) = y(x==0)

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by