I want to do
myCellArray = myCcellArray{indices} 
where indices is just 0s and 1s, with same number of elements as the number of rows in myCellArray, but it doesn't work. What should I do?
You need to use parenthesis instead of curly braces to do the indexing.
>> arr = cell(2,2);
>> arr{1,1} = magic(4);
>> arr{1,2} = 'Hello';
>> arr{2,1} = 42;
>> arr{2,2} = pi;
>> arr
arr = 
    [4x4 double]    'Hello' 
    [        42]    [3.1416]
>> idx = logical(zeros(2,2));
>> idx(1,1) = true;
>> idx(2,2) = true;
>> arr(idx)
ans = 
    [4x4 double]
    [    3.1416]
                        If you want to slice a cell-array, use parentheses. Example:
%# random cellarray of strings, and a logical indices vector
myCcellArray = cellstr(num2str((1:10)','value %02d'));   %'
indices = rand(size(myCcellArray)) > 0.5;
%# slicing
myCellArray = myCcellArray(indices)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With