Multiply two cell arrays
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
lucksBi
el 28 de Feb. de 2018
Comentada: Stephen23
el 28 de Feb. de 2018
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 comentarios
Stephen23
el 28 de Feb. de 2018
lucksBi: I did not ask you for the size of mul1 or mul2. Please read my comment again.
Respuesta aceptada
Birdman
el 28 de Feb. de 2018
Try this:
res=cellfun(@times,mul1,mul2,'uni',0)
3 comentarios
Andrei Bobrov
el 28 de Feb. de 2018
Editada: Andrei Bobrov
el 28 de Feb. de 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]
>>
Más respuestas (0)
Ver también
Categorías
Más información sobre Multidimensional Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!