how to get the result as a vector
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, Im generating normal random numbers into a matrix and then perform a calculation on each column of the matrix. My problem is that the result is just a single number and should be a vector of numbers one for each column. here is my code
Y=sort(randn(500,10));
Z=zscore(Y);
q=size(Y);
j = [1:q(1)];
result = -q(1)-(1/q(1))*sum((j*2-1).*(log(normcdf(Z(j),0,1))+log(1-normcdf(Z(q(1)+1-j),0,1))))
The "result" just comes out as a single number where as I'm trying to get it as a vector, in the above code a vector with 10 entries.
Where am I going wrong?
댓글 수: 0
채택된 답변
Oleg Komarov
2011년 9월 3일
n = size(Y,1);
j = 1:n;
result = -n-(1/n)*sum(bsxfun(@times,j.'*2-1, log(normcdf(Z,0,1))+log(1-normcdf(Z(end:-1:1,:),0,1))))
댓글 수: 0
추가 답변 (1개)
Andrei Bobrov
2011년 9월 3일
result = -q(1)-(1:2:q(1)*2)*(log(normcdf(Z,0,1))+log(1-normcdf(Z(q(1):-1:1,:),0,1)))/q(1)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!