How to add 1 into the array

조회 수: 3 (최근 30일)
fyza affandi
fyza affandi 2018년 12월 7일
답변: Star Strider 2018년 12월 7일
I have an array
M =[1 0 0]
How can I add 1 into the array so the answer will be
N=[1 0 1]
If I add other 1, the answer will be
O = [1 1 0]

채택된 답변

Star Strider
Star Strider 2018년 12월 7일
Try this:
binadd = @(a,b) dec2bin(bin2dec(a) + bin2dec(b)); % Create Function
M = '100';
N = binadd(M, num2str(1))
O = binadd(N, num2str(1))
producing:
N =
'101'
O =
'110'
To create a numeric array, subtract '0':
Onum = O - '0'
Onum =
1 1 0

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 12월 7일
편집: madhan ravi 2018년 12월 7일
O = M==N

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by