How to sum over indexed arrays

4 次查看(过去 30 天)
Lucius
Lucius 2015-5-23
编辑: Lucius 2015-5-24
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 个评论
Lucius
Lucius 2015-5-24
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?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2015-5-23

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by