how i can put the (-1) in binary matrix with condition ?
1 回表示 (過去 30 日間)
古いコメントを表示
how i can put (-1) after and before any group of ones in matrix like this
before code A = [ 1 1 0 0 0 1 0 1 1
0 1 1 0 0 0 0 1 1
0 0 1 1 0 0 1 0 0 ]
after code A* = [ 1 1 -1 0 -1 1 -1 1 1
-1 1 1 -1 0 0 -1 1 1
0 -1 1 1 -1 -1 1 -1 -1 ]
1 件のコメント
Azzi Abdelmalek
2016 年 4 月 9 日
編集済み: Azzi Abdelmalek
2016 年 4 月 9 日
The last value of A* is not correct
採用された回答
Azzi Abdelmalek
2016 年 4 月 9 日
編集済み: Azzi Abdelmalek
2016 年 4 月 9 日
A = [ 1 1 0 0 0 1 0 1 1
0 1 1 0 0 0 0 1 1
0 0 1 1 0 0 1 0 0 ]
for k=1:size(A,1);
id_before=strfind(A(k,:),[0 1])
id_after=strfind(A(k,:),[1 0])+1
A(k,[id_before id_after])=-1
end
0 件のコメント
その他の回答 (1 件)
Kuifeng
2016 年 4 月 9 日
% is the last number in your A* equal to 0 instead?
%the following code may work
[rows cols] = size(A);
A_diff = A(:,1:end-1)-A(:, 2:end);
A(find(A_diff == -1)) = -1;
A(find(A_diff == 1)+rows) = -1;
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!