Remove rows using Cellfun satisfying customised function

1 visualización (últimos 30 días)
NS
NS el 7 de En. de 2019
Comentada: Image Analyst el 8 de En. de 2019
I have a cellarray A which has 10 columns of which i need to apply this below mentioned condition on the 8th column of each cell and then remove those rows in each cell that meets the condition.
[idx1] = cellfun(@(x)abs(x - mean(x)) > 3*std(x),A(:,8),'UniformOutput',false));
[idx1] = cellfun(@(x)abs(x - mean(x)) > 3*std(x),A(:,8),'UniformOutput',false));
Error: Unbalanced or unexpected parenthesis or bracket.
I get error index exceeds matrix dimension.
How to perform this using cellfun and remove the rows from each cell?
  5 comentarios
Jan
Jan el 7 de En. de 2019
You cannot get two errors. If there is an unbalanced parenthesis, the code does not run at all, such that you cannot get an index problem. Please post the code and a copy of the complete error message.
NS
NS el 7 de En. de 2019
Sorry for confusion, yes i am getting one error , i have updated the code and error.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 7 de En. de 2019
A bold guess: You have redefined abs, mean or std by a variable. Then trying to access these functions must fail. Check this using the debugger:
dbstop if error
Then run the code again until it stops at the error. Now check the names in the command window:
which abs -all
which mean -all
which std -all
By the way: Do you really want the curly braces inside the cellfun argument? And:
{abs(x - mean(x) > 3*std(x))}
is strange: Shouldn't the abs() contain the x-mean(x) only? What are the elements of the 8.th column? Vectors or scalars?
  6 comentarios
Jan
Jan el 7 de En. de 2019
Editada: Jan el 7 de En. de 2019
@NS: This is, as far as I can see, another error. The problem with the parenthesis is fixed. I suggetsed 2 hours ago to use the debugger to find out, if you have redefined one of the functions. Example:
clear all
x = 1:10
mean(x)
mean = 'hello'
mean(x) % ERROR: 'hello' does not have 10 characters
Or maybe A does not have 8 columns in opposite to your expectations?
The debugger is the best friend of the programmer. Whenever a problem occurs, it helps to identify, what's going on. While the forum has to guess the not shown details, the debugger knows the dimension and classes of all symbols.
"Class of 8th column is double." - and the dimensions?
Image Analyst
Image Analyst el 8 de En. de 2019
Please save A into a .mat file and attach it with the paper clip icon so we can solve this and quit guessing.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by