MATLAB: How to populate a cell array with vector elements

cell arraysvectors

I have a cell array consisting of n-number of cells, each of different size. I also have a vector consisting of n-number of elements. I'd like to populate the cells with the corresponding elements from the vector.

Best Answer

What have you tried so far? This is easy with a loop:
C = {ones(1, 3); ones(1, 7); ones(1, 5)};
x = [3; 5, 7];
for k = 1:numel(C)
C{k} = C{k} * x(k);
end
There are some alternatives, which might be needed, if this is a homework question. Hint:
index = [1,1,1];
value = 8;
value(index)