Sum subarrays of a Matrix.

Hi Matlabsolutions community! Could someone give me a hand?

I’m having trouble trying to sum parts of the arrays of a matrix. Let’s say I have the following matrix A of r rows and c columns (rxc).

A = [1,2,3,4,5,6,7,8,9; 10,11,12,13,14,15,16,17,18; 19,20,21,22,23,24,25,26,27]

And what I would like to to is to divide each array in n subarrays (n=3) and sum each of those subarrays. In this case, it would be the sum of every three positions. Getting an output suchs as:

out = [5,15,24; 33,42,51; 60,69,78]

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

One-liner

transpose(reshape(sum(reshape(A',3,[])),3,[]))

Or

transpose(cell2mat(cellfun(@sum,mat2cell(A',[3,3,3],3),'unif',0)))

--

--

--

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Week of 28 Feb — 6 Mar

28 — Intro to Landing Zones

28 — Intro to Landing Zones

How do I change default solver preferences for models in Simulink 6.5 (R2006b)?

Baking Bread and the Unix Shell

Why You Should Consider Angular Development For Your design

Setup Oracle Graph on Cloud (DBCS)

Effective Agile + Waterfall Hybrid Project Management

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Technical Source

Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

More from Medium

What’s the most efficient way to isolate a connected

Normalization VS Standardization a Pre- processing Techniques in Machine Learning

Neural Networks: Inside the Black Box

Breaking news:ML can help detect fake news and this isn’t fake news 😉