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

3 ビュー (過去 30 日間)
CodeJunkie
CodeJunkie 2019 年 1 月 29 日
コメント済み: CodeJunkie 2019 年 1 月 29 日
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

採用された回答

Guillaume
Guillaume 2019 年 1 月 29 日
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
  2 件のコメント
Luna
Luna 2019 年 1 月 29 日
@Guillaume +1 :)
CodeJunkie
CodeJunkie 2019 年 1 月 29 日
Thanks again I appeciate the help.

サインインしてコメントする。

その他の回答 (1 件)

Luna
Luna 2019 年 1 月 29 日
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})')';

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by