How to multiply a matrix to another cell matrix
34 ビュー (過去 30 日間)
古いコメントを表示
Hello
I have a 3*3 matrix such as
[1 0 0;
8 23 1;
5 7 10]
On the other hand, I have matrix 2000*1 containing 2000 cell arrays which are 3*4 matrices such as
[ [3*4];
[3*4];
[3*4];
.
.
]
I want to multiplythis 3*3 matrix to each of 3*4 matrices in the big matrix and obtain a final 2000*1 matrix. I have seen the code @(x)x.*matrix in MATLAB forum.
However, it gives out a function handle..I need to use the numeric output. What should i do?
1 件のコメント
David Hill
2021 年 5 月 14 日
You need to explain more. How are you getting a 2000x1 matrix? What do you mean when you say multiply? 3x3 * 3x4 = 3x4 matrix, you cannot perform element-wise multiplication on different sized matrices.
採用された回答
その他の回答 (1 件)
Jan
2021 年 5 月 14 日
編集済み: Jan
2021 年 5 月 14 日
Create a simple loop:
A = rand(3, 3);
for iC = 1:numel(C) % Where C is your cell
C{iC} = A * C{iC};
end
The approach with cellfun looks smart, but it is slower:
C = cellfun(@(c) A*c, C, 'UniformOutput', false);
By the way, .* is the elementwise operation. You need *, because the matrix and the cell elements do not have the same number of elements.
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!