Borrar filtros
Borrar filtros

How to add cell arrays?

2 visualizaciones (últimos 30 días)
Darsana P M
Darsana P M el 21 de Nov. de 2017
Comentada: Walter Roberson el 21 de Nov. de 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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Nov. de 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 comentarios
Darsana P M
Darsana P M el 21 de Nov. de 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 el 21 de Nov. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by