Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8918343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:43:38+00:00 2026-06-15T05:43:38+00:00

I have a cell array of cell(1, n) called A , with each cell

  • 0

I have a cell array of cell(1, n) called A, with each cell entry containing a matrix of mxn. So, in effect, my cell array contains n matrices of size mxn.

I then have another cell array called B, with n pxm matrices stored in it.

What I need to do is multiply the two against each other, as in: A[1] * B[1], A[2] * B[2], …, A[n] * B[n]. I then need to store the results as individual matrices of their own, and sum them up.

The matrices are conformal for multiplication, but because cell array B contains less rows than cell array A, when I use cellfun(@times A, B, 'UniformOutput', true) I get an unequal matrices error.

This seems to indicate that cellfun can only multiply individual cells when the matrices have equal numbers of rows and columns.

Now, I could perform this by using various loops, or by calling cell2mat and mat2cell, and so on. I could also just store everything as a matrix array rather than using cells… but – I would prefer to use cells.

So – my question is: Is there a good way of doing this using only cellfun? I have tried various combinations of argument inputs already – but with no luck so far.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:43:40+00:00Added an answer on June 15, 2026 at 5:43 am

    To do this with cellfun, just define your own anonymous function:

    C = cellfun(@(a,b) a*b, A, B, 'UniformOutput', 0);
    

    Now, as you posed the question, you cannot multiply A*B, because the inner dimensions don’t agree. Instead, I tested this with B*A, where the dimensions do agree: p=1, m=3, n=3.

    A = {eye(3), rand(3), magic(3)};
    B = {[1 2 3], [3 5 1], [7 8 8]};
    
    C = cellfun(@(a,b) b*a, A, B, 'UniformOutput', 0);
    
    Cmat = cat(3, C{:});
    S = sum(Cmat, 3);
    

    The sum is done by concatenating each array of C over a third dimension then summing over it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cell array which contains 7 matrices of varying column and length
I have a 1-dimensional cell array Z. Each cell of Z contains a vector.
I have three arrays, all the same size: xout % cell array xin %
I have a 4902x1 cell array which contains strings like Blue. or Green. I
Say I have a cell array, that holds a stack of logical matrices, e.g.
I have an array called as myArr . It contains strings and integers, e.g.
Hi I have a cell array which is called vector , with dimensions 69083x2
I have a cell array of anonymous function handles, and would like to create
I have a Matlab function that creates a cell array with matrixes inside. It
You have: val array = new Array[Array[Cell]](height, width) How do you initialize all elements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.