# how to get the result as a vector

조회 수: 10(최근 30일)
john birt 2011년 9월 3일
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?

댓글을 달려면 로그인하십시오.

### 채택된 답변

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))))

댓글을 달려면 로그인하십시오.

### 추가 답변(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)

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!