我需要计算矩阵的平均值,但只计算那些大于指定数的值。现在我带着这样的想法:
Media = mean(W_tot_migl,2);
H = W_tot_migl;
H(H<LimiteInferiore) = nan;
Media_b = nanmean(H,2);有没有办法避免创建另一个矩阵H = W_tot_migl?
发布于 2013-09-24 07:59:51
从你想要的评论来看:
H = magic(5); %Suppose this is your matrix
LimiteInferiore = 23; %And suppose this is your treshold
Media_b= NaN(size(H,1),1); %Or perhaps zeros, whatever you like to show by default
idx = any(H > treshold,2);
Media_b(idx) = mean(H(H>treshold),2);如果它存在,它将给出行平均值,而NaN则给出其他值。我相信您不需要NaN平均值,因为NaN值不会计算为>treshold。
https://stackoverflow.com/questions/18975460
复制相似问题