Roundation In Binary Problem

Hello everyone, I need a programme help. I think it will be obvious if I will examine it with an example.
Consider we have a matrix (6x6) in binary;
0 0 1 0 1 0
0 1 1 0 1 1
y= 1 0 0 0 1 0
0 1 0 1 1 0
0 0 0 1 0 1
0 0 0 0 0 1
I would like to make roundation. Means it will look the rows' one by one, if the last number is 1, it will add 1 to the number (in binary) and in the end it will return matrix 5x5 (for this example).
For this example:
0 0 1 0 1
0 1 1 1 0
y= 1 0 0 0 1
0 1 0 1 1
0 0 0 1 1
0 0 0 0 1
And it should do it for any matrix which is (nxn)
Thanks from now ;)

댓글 수: 2

Walter Roberson
Walter Roberson 2012년 11월 6일
What code have you tried?
Image Analyst
Image Analyst 2012년 11월 6일
I don't understand. I've never heard of "roundation". What does "Add 1 to the number in binary" mean? If it's binary (logical) adding 1 will still leave it at 1 - it will get clipped. And how does doing that chop off the last column?

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2012년 11월 6일
편집: Matt J 2012년 11월 6일

0 개 추천

out = dec2bin( y(:,1:end-1)*2.^((n-2:-1:0).') + y(:,end) )-'0';

댓글 수: 1

Turgut
Turgut 2012년 11월 6일
thank you so much it works perfect ;)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

2012년 11월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by