How to sum over indexed arrays

2 views (last 30 days)
Lucius
Lucius on 23 May 2015
Edited: Lucius on 24 May 2015
I have 3 arrays of the same dimension, having the same name but with indexes. How can one sum over the elements.
clear all; close all;
It=3; %Number of created arrays
for ii=1:It
a(ii) = [1 1 rand()]
end
abc = zeros(size(a(1))); %array abc has zero entries of same dimension as the a-arrays
for ii = 1:It %summation over a-arrays
abc = abc + a(ii)
end
abc %final array with summed elements
What is wrong with it?
  7 Comments
Lucius
Lucius on 24 May 2015
This seems to work in the sense that the programm goes into both of my for-loops. Can you tell me why the imgs in your example has the format 4-D uint8 instead of being 3D? That gave me the error message that "Integers can only be combined with integers of the same class, or scalar doubles." What I try now is putting your imgs into double(imgs). Any recommendations?
Lucius
Lucius on 24 May 2015
Edited: Lucius on 24 May 2015
-

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 23 May 2015

Products

Community Treasure Hunt

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

Start Hunting!