std of a logical matrix

1 visualizzazione (ultimi 30 giorni)
Andrea
Andrea il 13 Lug 2012
I have a 2d matrix (100 by 4 )and I want to calculate the std for each 100 by 1 non-zero vector of this matrix,. But when i wrote std(y)---. it gave me a 1 by 4 matrix as a result. It is good but I want to compute the std for non-zero elements. Then I wrote std(y(y>0))-----------. it gives me a single value as a std and not a 1 by 4 vector. Please help me regarding that issue.
Kind Regards, Andrea

Risposta accettata

Kye Taylor
Kye Taylor il 13 Lug 2012
sigmasPositive = zeros(1,4);
for j = 1:size(y2D,2)
idxOfInterest = y2D(:,j) > 0;
sigmasPositive(j) = std(y2D(idxOfInterest,j));
end
or you can avoid the loop using
z = mat2cell(y2D,size(y2D,1),ones(1,size(y2D,2)));
sigmasPositiveNoLoop = cellfun(@(c)std(c(c>0)),z);

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by