arrayfun doesn't work with rmoutliers
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Goal
Remove outliers along dimension d of a 3D matrix using arrayfun and rmoutliers (or superior alternatives).
Minimal Working Example
Take the following matrix:
A = [0 2 0 0 0; 0 0 0 4 0; 3 0 0 3 0];
A(:,:,2) = A
Since each 1D array along dimension d will have a different number of outliers, the output of arrayfun will have to be a cell array (by specifying "UniformOutput" = false). Calling rmoutliers through arrayfun returns the original matrix with the outliers (undesired behaviour):
arrayfun(@rmoutliers,A,"UniformOutput",false)
The function works as expected when called on each row by itself:
rmoutliers(A(1,:,1)) % removes the 2
rmoutliers(A(3,:,1)) % removes both 3's
Hopefully I'm missing something trivial.
0 Kommentare
Akzeptierte Antwort
Voss
am 5 Jan. 2022
A = [0 2 0 0 0; 0 0 0 4 0; 3 0 0 3 0];
A(:,:,2) = A
C = num2cell(A,2)
cellfun(@rmoutliers,C,"UniformOutput",false)
Weitere Antworten (1)
Mike Croucher
am 5 Jan. 2022
arrayfun operates on every element of the array. So
arrayfun(@rmoutliers,A,"UniformOutput",false)
is like doing
rmoutliers(0)
rmoutliers(0)
rmoutliers(3)
etc
1 Kommentar
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!