Borrar filtros
Borrar filtros

Changing blocks in a cell array

1 visualización (últimos 30 días)
Krzysztof
Krzysztof el 25 de Ag. de 2011
Hi,
I have a cell array which holds strings in certain columns and numerical values (doubles) in others. Can I change a whole block of numerical values in the cell array in one line of code (e.g. X(1:10,2) = ones(1,10), where X is a cell array) or do I need to do this using a "for" loop, repeating X{i,2} = 1 each time?
Thanks,
~K

Respuesta aceptada

Desiree
Desiree el 25 de Ag. de 2011
You can do:
X(1:10,2) = num2cell(ones(1,10));
or:
X(1:10,2) = {1};
The class of the left hand side and right hand side of the assignment just need to be consistent in order for this to work in one line of code.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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