std of a logical matrix

1 Ansicht (letzte 30 Tage)
Andrea
Andrea am 13 Jul. 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

Akzeptierte Antwort

Kye Taylor
Kye Taylor am 13 Jul. 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);

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by