Filter löschen
Filter löschen

Changing blocks in a cell array

1 Ansicht (letzte 30 Tage)
Krzysztof
Krzysztof am 25 Aug. 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

Akzeptierte Antwort

Desiree
Desiree am 25 Aug. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by