Changing blocks in a cell array
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Desiree
on 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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!