How do I replace/convert all zeros in 3rd-dimension to NaN

1 回表示 (過去 30 日間)
NA
NA 2020 年 9 月 5 日
コメント済み: NA 2020 年 9 月 5 日
Hi All,
I have a 5-D matrix: 5x16x20x3x15, where 5x16 is the data set; 20 is the number of trials (per experiment); 3 is the number of experiments (per participant); and 15 is the number of participants. If I had 1 particant that had a dataset (for only one exp) that was exclusively all zeros i.e. 5x16x20x2x2 was entirely zeros; would there be a way to convert the zeros to NaN, so that my mean and std calculations are not affected?
Cheers.

採用された回答

David Hill
David Hill 2020 年 9 月 5 日
yourMatrix(:,:,affectedTrials,affectedExperiment,affectedParticipant)=nan;
If all trials of the affected experiment are zeros, then:
yourMatrix(:,:,:,2,2)=nan;
  3 件のコメント
David Hill
David Hill 2020 年 9 月 5 日
If your matrix is not too large, this will work fine.
for k=1:size(yourMatrix,3)
for n=1:size(yourMatrix,4)
for m=1:size(yourMatrix,5)
if nnz(yourMatrix(:,:,k,n,m))==0
yourMatrix(:,:,k,n,m)=nan;
end
end
end
end
NA
NA 2020 年 9 月 5 日
thanks mate

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation of 2-D Selections in 3-D Grids についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by