how to get the result as a vector

조회 수: 1 (최근 30일)
john birt
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
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
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)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by