MATLAB: How to use Prod function with cell arrays

arraycell arraysMATLAB

I have defined a cell array in the name of "T_mn" having "n_layers" number of cells.
Each cell is having a vector containing "n_modes" elements.
I want to find the product of element "req_mode" in each vector among the cells between "wire_lay" – "obs_lay"
when I though of using this code it is not working
for wire_lay=1:1:n_layers
for req_mode=1:1:l_modes
for obs_lay=1:1:n_layers
A=prod(T_mn{wire_lay:1:obs_lay}(req_mode))
end
end
end
Can you help?

Best Answer

% Extract the value in index "req_mode" from each cell in "T_mn"
% starting and ending at cell index "wire_lay" and "obs_lay" respectively.
wire_lay = 2;
obs_lay = 4;
req_mode = 3;
vec = cellfun(@(x)x(req_mode),T_mn(wire_lay:obs_lay));
prd = prod(vec);
% DEMO data
T_mn{1} = [1 2 3 4];
T_mn{2} = [5 6 7 8];
T_mn{3} = [9 10 11 12];
T_mn{4} = [13 14 15 16];
T_mn{5} = [0 0 0 0 ];