Multiply two cell arrays
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi i have following two cell arrays mul1 and mul2.
I want to multiply each cell of mul1 with corresponding cell of mul2. I am using following code
for i=8
for j=7
mul3{i,j}= mul1{i,j}.*mul2{i,j};
end
end
but it gives error:
Error using .*
Matrix dimensions must agree.
i also tried without using loop but still same issue.
Please help
3 Commenti
Stephen23
il 28 Feb 2018
lucksBi: I did not ask you for the size of mul1 or mul2. Please read my comment again.
Risposta accettata
Birdman
il 28 Feb 2018
Try this:
res=cellfun(@times,mul1,mul2,'uni',0)
3 Commenti
Andrei Bobrov
il 28 Feb 2018
Modificato: Andrei Bobrov
il 28 Feb 2018
@lucksBi: All right!
>> mul1
mul1 =
8×7 cell array
[1×0 double] [ -0.1140] [ -0.2700] [1×2 double] [1×2 double] [] []
[1×0 double] [1×0 double] [1×3 double] [ 0.1967] [1×0 double] [1×2 double] [1×4 double]
[ -0.1140] [1×0 double] [1×0 double] [1×3 double] [1×2 double] [1×0 double] [1×3 double]
[ -0.2700] [1×3 double] [1×0 double] [1×0 double] [ 0.2598] [ -0.8066] [1×3 double]
[1×2 double] [ 0.1967] [1×3 double] [1×0 double] [1×2 double] [ -0.0151] [1×4 double]
[1×2 double] [1×0 double] [1×2 double] [ 0.2598] [1×2 double] [1×0 double] [1×2 double]
[1×0 double] [1×2 double] [1×0 double] [ -0.8066] [ -0.0151] [1×0 double] [1×2 double]
[ -0.0974] [1×4 double] [1×3 double] [1×3 double] [1×4 double] [1×2 double] [1×2 double]
>> mul2
mul2 =
8×7 cell array
[] [ 1] [ 1] [1×2 double] [1×2 double] [] []
[] [] [1×3 double] [ 1] [] [1×2 double] [1×4 double]
[ 1] [] [] [1×3 double] [1×2 double] [] [1×3 double]
[ 1] [1×3 double] [] [] [ 1] [ 1] [1×3 double]
[1×2 double] [ 1] [1×3 double] [] [1×2 double] [ 1] [1×4 double]
[1×2 double] [] [1×2 double] [ 1] [1×2 double] [] [1×2 double]
[] [1×2 double] [] [ 1] [ 1] [] [1×2 double]
[ 1] [1×4 double] [1×3 double] [1×3 double] [1×4 double] [1×2 double] [1×2 double]
>> cellfun(@times,mul1,mul2,'un',0)
ans =
8×7 cell array
[] [ -0.1140] [ -0.2700] [1×2 double] [1×2 double] [] []
[] [] [1×3 double] [ 0.1967] [] [1×2 double] [1×4 double]
[ -0.1140] [] [] [1×3 double] [1×2 double] [] [1×3 double]
[ -0.2700] [1×3 double] [] [] [ 0.2598] [ -0.8066] [1×3 double]
[1×2 double] [ 0.1967] [1×3 double] [] [1×2 double] [ -0.0151] [1×4 double]
[1×2 double] [] [1×2 double] [ 0.2598] [1×2 double] [] [1×2 double]
[] [1×2 double] [] [ -0.8066] [ -0.0151] [] [1×2 double]
[ -0.0974] [1×4 double] [1×3 double] [1×3 double] [1×4 double] [1×2 double] [1×2 double]
>>
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Multidimensional Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!