how can I create 10 different gaussian random vectors (X) and sum them, after their square elevation (Y = X1^2 + X2^2 + ... X10^2)?
    1 次查看(过去 30 天)
  
       显示 更早的评论
    
    if true
      % code
  % be Y = X1^2 + X2^2 + ... XM^2
N = 10000;
M = 10;
Y=zeros(N,1);
for j=1:length(M)
    X=(randn(N,1));
    Y=Y(j)+X.^2;
end
  end
0 个评论
回答(1 个)
  Image Analyst
      
      
 2016-7-12
        Try this:
N = 10000;
M = 10;
X = randn(N, M);
XSquared = X .^ 2;
% Perhaps this is wanted:
Y = sum(XSquared, 1)
% Or maybe this is wanted:
Y = sum(XSquared(:))
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
			
	产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

