How to add cell arrays?
1 次查看(过去 30 天)
显示 更早的评论
IV={'ca' 'fe' 'ba' 'be' 'fa' 'ce' 'db' 'ad' 'de' 'ca' 'f8' '88' '00' '01'}
The expected output is:
IV={'ca' 'fe' 'ba' 'be' 'fa' 'ce' 'db' 'ad' 'de' 'ca' 'f8' '88' '00' '02'} ie only incrementing the value at the end??
What must be the matlab code?
0 个评论
采纳的回答
Walter Roberson
2017-11-21
IV = {'ca' 'fe' 'ba' 'be' 'fa' 'ce' 'db' 'ad' 'de' 'ca' 'f8' '88' '00' '01'};
y = {'00' '00' '00' '00' '00' '00' '00' '00' '00' '00' '00' '00' '00' '01'};
x_numeric = cellfun(@(x) sscanf(x, '%x'), IV);
y_numeric = cellfun(@(x) sscanf(x, '%x'), y);
xplusy_numeric = x_numeric + y_numeric;
xplusy_cell = sprintfc('%02x', xplusy_numeric);
... I predict you are going to change the question once you think about this for a few minutes.
2 个评论
Walter Roberson
2017-11-21
IV = {{'ca' 'fe' 'ba' 'be' 'fa' 'ce' 'db' 'ad' 'de' 'ca' 'f8' '88' '00' '01'}};
y = {'00' '00' '00' '00' '00' '00' '00' '00' '00' '00' '00' '00' '00' '01'};
x_numeric = cellfun(@(x) sscanf(x, '%x'), IV{1});
y_numeric = cellfun(@(x) sscanf(x, '%x'), y);
for K = 2 : 3
x_numeric = x_numeric + y_numeric;
IV{K} = sprintfc('%02x', x_numeric);
end
Now look at IV{1}, IV{2}, IV{3}
... and I still predict that you are going to change the question once you think about it for a few minutes.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!