Multiplying a matrix in a cell by another matrix in the same cell

3 visualizaciones (últimos 30 días)
RU and Difference are 5x1 cells, each cell has a (25,1) double inside of it. I would like to multiply cell RU{1,1} by RU{2,1} by RU{3,1 }until RU{n,1} and the same for difference. By my estimation that would give me a (25,1) double or a 1x1 cell depending on how you do it. Ive tried looping it as well as cellfun and mat2cell and cell2mat but have not been able to solve this issue. Any help anyone can lend would be much appreciated.
%% **
PRU=cell(1,1)';
PD=cell(1,1)';
for iter=1:n
PRU{1,1} =RU{iter,1}*RU{iter+1,1}
PD{1,1} =Difference{iter,1}*Difference{iter+1,1}
end

Respuesta aceptada

Guillaume
Guillaume el 29 de En. de 2019
Since each cell array contains matrices that are all the same size (in this case, column vectors), you would make your life much easier by using matrices instead of cell arrays. Your multiplication operation would then be trivial
RUasmatrix = [RU{:}]; %convert 5x1 cell array of 25x1 column vectors into a 25x5 matrix
PRU = prod(RUasmatrix, 2) %multiply all the columns. No point in storing that in a cell array

Más respuestas (1)

Luna
Luna el 29 de En. de 2019
Try this:
RU = {randi(20,25,1),randi(20,25,1),randi(20,25,1),randi(20,25,1),randi(20,25,1)}';
result = prod(horzcat(RU{1:numel(RU),1})')';

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by