Azzera filtri
Azzera filtri

how to get the result as a vector

2 visualizzazioni (ultimi 30 giorni)
john birt
john birt il 3 Set 2011
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?

Risposta accettata

Oleg Komarov
Oleg Komarov il 3 Set 2011
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))))

Più risposte (1)

Andrei Bobrov
Andrei Bobrov il 3 Set 2011
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)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by