フィルターのクリア

std of a logical matrix

2 ビュー (過去 30 日間)
Andrea
Andrea 2012 年 7 月 13 日
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

採用された回答

Kye Taylor
Kye Taylor 2012 年 7 月 13 日
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);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by