Filter löschen
Filter löschen

How to add cell arrays?

2 Ansichten (letzte 30 Tage)
Darsana P M
Darsana P M am 21 Nov. 2017
Kommentiert: Walter Roberson am 21 Nov. 2017
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 21 Nov. 2017
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 Kommentare
Darsana P M
Darsana P M am 21 Nov. 2017
Sir, Actually i wanted to increment the cell array, IV, such that the output will be as follows:
IV 1= {'ca' 'fe' 'ba' 'be' 'fa' 'ce' 'db' 'ad' 'de' 'ca' 'f8' '88' '00' '01'};
IV 2 = {'ca' 'fe' 'ba' 'be' 'fa' 'ce' 'db' 'ad' 'de' 'ca' 'f8' '88' '00' '02'};
IV 3 = {'ca' 'fe' 'ba' 'be' 'fa' 'ce' 'db' 'ad' 'de' 'ca' 'f8' '88' '00' '03'};
and so on. Thanks for the reply.Is there a simpler way??
Walter Roberson
Walter Roberson am 21 Nov. 2017
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by