MATLAB: Divide a cell arrays with a part of another cell array

divide cell arrays

Hi everyone,
I want to divide a cell array A, 2×100 with the last 100 elements of another cell array B 1×101.All of the elements of both cell arrays are scalars. I have tried
c=num2cell(cell2mat(A)./cell2mat(B{1,2:end}));
but it doesn't work. Thanks in advance.

Best Answer

Try this:
C = num2cell(bsxfun(@rdivide,cell2mat(A),cell2mat(B(1,2:end))));
Note that B{1,2:end} using the curly braces will be a comma-separated-list of the contents of B, whereas B(1,2:end) using parentheses will simply be another cell array.