MATLAB: How to replace multiple values with the same value in a cell array

cell arrays

I would like to replace multiple values with the same value in a cell array.
% retrieve a vector with logical values
index = contains(oversikt.Jernbanen, '395');
% find the indexes of the index vector where the logical values = 1
index2 = find(index == 1);
% replace all the values. / the error: "Expected one output from a curly brace or dot indexing expression, but there were 12 results."
oversikt.Jernbanen{1,index2} = '0';

Best Answer

The RHS must be a scalar cell.
The LHS must use parentheses, because you are replacing cells (not accessing their contents).
oversikt.Jernbanen(1,index) = {'0'};
Remember:
  • () parentheses refer to the cells themselves
  • {} curly braces refer to the cell contents.