How do I use a 2D logical index matrix to change a subset of a 3D array?
Ältere Kommentare anzeigen
I have data in a 11x100x11 array. I'm looking for outliers within the subsets along the third dimension, i.e. data(:,:,1), and want to replace them with NaNs. I use the following line:
cond = abs(data(:,:,1)) > threshold;
which produces a 11x100 matrix, cond. Now I'm trying to figure out how to appropriately use cond to index the values I want to change. If I use the following line:
data(cond,1) = NaN;
I get a 1100x100x11 array. How do I index with cond to cover two dimensions of my array?
Akzeptierte Antwort
Weitere Antworten (2)
James Tursa
am 31 Mär. 2015
Bearbeitet: James Tursa
am 31 Mär. 2015
data(cond(:)) = nan; % Use linear indexing since target is 1st plane
3 Kommentare
Debra
am 31 Mär. 2015
James Tursa
am 31 Mär. 2015
Bearbeitet: James Tursa
am 31 Mär. 2015
My Answer was based on this line, data(cond,1) = NaN, where it looked to me like you only wanted to change the 1st plane. If you wanted to have different thresholds for each plane and apply them separately, then I would have suggested:
thresholds = 11-element threshold vector for each plane
cond = bsxfun(@gt,abs(x),reshape(thresholds,1,1,[]));
data(cond) = nan;
But, frankly, I am still not sure what you are after since I am not sure what you mean by "... each have their own set of conditions ..."
Debra
am 31 Mär. 2015
Sean de Wolski
am 31 Mär. 2015
Bearbeitet: Sean de Wolski
am 31 Mär. 2015
0 Stimmen
Why not just use a for loop over slices...?
2 Kommentare
Debra
am 31 Mär. 2015
Rogier Westerhoff
am 26 Mär. 2017
I am struggling with the same. It also makes the whole loop quite slow if you have to do this over many pages. Hopefully Mathworks will find a solution for this soon?
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!