How to add 1 into the array
1 次查看(过去 30 天)
显示 更早的评论
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]
0 个评论
采纳的回答
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
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!