logicals and replacing values in 3D matrices

1 回表示 (過去 30 日間)
Chad Greene
Chad Greene 2014 年 2 月 28 日
回答済み: Azzi Abdelmalek 2014 年 2 月 28 日
I have three matrices. Their sizes are as follows:
x is m x n.
y is m x n.
z is m x n x q.
I can redefine all the values in y corresponding to x=2 by y(x==2)=NaN. I'd like to do this for all the corresponding values of z as well. It seems simple, but how do I do this? z(x==2,:) does not work.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 2 月 28 日
[ii,jj]=find(x==2)
kk=repmat((1:numel(ii))',1,q)';
idx=sub2ind(size(z),repmat(ii,q,1),repmat(jj,q,1),kk(:))
z(idx)=nan

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by