How to ignore certain columns in a matrix when calculating a mean across all columns in a matrix?
16 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I have a 100x16 double matrix (attached) which when plotted over one figure looks like this.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/929169/image.jpeg)
Now, I want to calculate the mean across all columns in the matrix so that the output is a 100x 1 double. I can do this by following
load 'data'
figure
plot(S_or_z(:,1:8),'r')
hold on
plot(S_or_z(:,9:end),'b')
% get mean
S_or_z_meancycle = mean(S_or_z, 2);
However, when calcuating the mean, I would like ignore the columns indicated in red.
The rule that I would like to apply is that the columns which range (max-min) exceeds 200 should be ignored when calcuating the mean accross all columns.
Can you help please?
0 件のコメント
採用された回答
Davide Masiello
2022 年 3 月 16 日
編集済み: Davide Masiello
2022 年 3 月 16 日
See if this works
new_S_or_z = S_or_z(:,(max(S_or_z,[],1)-min(S_or_z,[],1)) < 200);
plot(new_S_or_z)
mean(new_S_or_z,[],2)
2 件のコメント
Davide Masiello
2022 年 3 月 16 日
Yes, you're right! I got the syntax for "min" and "max" mixed up with the one for "mean", sorry about that.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!