How to multiply elements of a cell array with each other?

2 views (last 30 days)
Hi,
I have a 1xN cell array with each cell containing 2x2 matrix. I want to now multiply the individual cell arrays to get a single matrix. I used the following code but it is just multiplies the last two:
prompt = 'enter number of transformations'
N = input(prompt); %to enter number of matrixes user wants to multiply
A = cell(1,N);
%storing matrices in a 1xN cell array
for i = 1:1:N
prompt = 'enter transformation matrix'
A{1,i} = input(prompt);
end
%want to get a single multiplication matrix of all N cells
for i = 1:1:N
T = A{1,i}*A{1,:i+1};
end

Accepted Answer

Jos (10584)
Jos (10584) on 14 May 2016
You should be aware that matrix multiplication is not commutative (A*B does not equal B*A, in general). A for-loop is the best option
T = A{1} ;
for k = 2:numel(A)
T = T * A{k}
end
  2 Comments
kundunium
kundunium on 14 May 2016
Edited: kundunium on 14 May 2016
Thanks for the solution :) I am a complete noob with MATLAB
Jonas Holfelt
Jonas Holfelt on 26 Sep 2018
Any idea how you would perform this, defined as a function handle?

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!