Matrix‎ > ‎

Cell array

How to assign a single value to multiple cells

Cell arrays

set all cells to 'A'
ERROR: The right hand side of this assignment has too few values to satisfy the left hand side.

theoretically, we could use the command deal  to expand 'A' to the number we need.

better and easier: converting string 'A' to a cell {'A'} that is mapped to all selected cells(:) of s
    'A'    'A'    'A'    'A'    'A'

Example: replace all 'C' with 'A'
s = {'C','B','C','B','C'};
idx = ismember(s,'C');

    'A'    'B'    'A'    'B'    'A'

Numerical matrices

set all values smaller than 0.5 to zero

x = rand(2,4)
    0.8641    0.4547    0.7844    0.9137
    0.3889    0.2467    0.8828    0.5583

idx = x<0.5

    0.8641         0    0.7844    0.9137
         0         0    0.8828    0.5583