How to add 1 into the array

1 Ansicht (letzte 30 Tage)
fyza affandi
fyza affandi am 7 Dez. 2018
Beantwortet: Star Strider am 7 Dez. 2018
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]

Akzeptierte Antwort

Star Strider
Star Strider am 7 Dez. 2018
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

Weitere Antworten (1)

madhan ravi
madhan ravi am 7 Dez. 2018
Bearbeitet: madhan ravi am 7 Dez. 2018

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by