Changing blocks in a cell array

1 次查看(过去 30 天)
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

采纳的回答

Desiree
Desiree 2011-8-25
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by