MATLAB: Access subset of elements in a cell

cell arraysMATLABmatrix manipulation

I have created the following cell C from reading a txt file.
{["0719-3" ]} {["0729-2" ]} {["0742-5" ]} {["0742-6" ]} {["0744-5" ]} {["0744-6" ]}
{84444×4 double} {84444×4 double} {84444×4 double} {84444×4 double} {84444×4 double} {84444×4 double}
I want to switch the sign of the 2nd to 4th colums of each matrix (second row). Is there any way I can access all the submatrix (:,2:4) in the cell? I habe tried C{2,:}(:,2:4) (I was hoping to do something like C{2,:}(:,2:4) = -C{2,:}(:,2:4)but it does not work.

Best Answer

When typing
C{2,:}(:,2:4)
you are probably getting the error message "Expected one output from a curly brace or dot indexing expression, but there were 6 results" which pretty much explains what is happening. Note that
C{2,1}(:,2:4)
does not error.
You could use cellfun on C(2,:) as follows:
C = [{"A1"},{"A2"},{"A3"}; repmat({magic(4)},1,3) ]; % sample cell array
C(2,:) = cellfun(@(x) x.*[1,-1,-1,-1], C(2,:), 'UniformOutput', false);
>> C
C =
2×3 cell array
{["A1" ]} {["A2" ]} {["A3" ]}
{4×4 double} {4×4 double} {4×4 double}
>> C{2,1}
ans =
16 -2 -3 -13
5 -11 -10 -8
9 -7 -6 -12
4 -14 -15 -1