MATLAB Answers

Multiply cell by cell

34 views (last 30 days)
Tesla
Tesla on 17 Sep 2021 at 9:46
Commented: Tesla on 17 Sep 2021 at 10:43
I trying to muliply cell by cell.
Every cell has dimension 1001x1 and inside every cell I have 67x335 double.
So I want to multiply one by one. I tried with :
s=C_inside2.^2;
but I got this error:
Operator '.^' is not supported for operands of type 'cell'.

Accepted Answer

Jan
Jan on 17 Sep 2021 at 9:59
Edited: Jan on 17 Sep 2021 at 10:01
Use a loop:
for k = 1:numel(C_inside2)
C_inside2{k} = C_inside2{k} .^ 2;
end
This is faster than cellfun:
C_inside2 = cellfun(@(x) x.^2, C_inside2, 'uniformoutput', false);
  1 Comment
Tesla
Tesla on 17 Sep 2021 at 10:43
Thank you, it works!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!