Remove rows using Cellfun satisfying customised function

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 commentaires

kindly help.
Yes , its A(idx1)=[].
but the condition above it is giving error of index exceeding or Error: Unbalanced or unexpected parenthesis or bracket.
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.
Sorry for confusion, yes i am getting one error , i have updated the code and error.

Connectez-vous pour commenter.

Réponses (1)

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 commentaires

NS
NS le 7 Jan 2019
Modifié(e) : NS le 7 Jan 2019
Sir the 8th column is Prices.
And the curly brackets shouldnt be there but i am still not able to run the code. Gives same error as mentioned above.
Any solution sir ?
"Prices" is not a useful desciption of the contents of the 8th column. The physical meaning does not matter, but the class and dimensions of the variables.
Again: Please post the complete error message. You have mentione TWO errors, and this is impossible:
  1. Error: Unbalanced or unexpected parenthesis or bracket.
  2. I get error index exceeds matrix dimension.
Nevertheless, Matlab shows you exactly, where one problem is:
[idx1] = cellfun(@(x)abs(x - mean(x)) > 3*std(x),A(:,8),'UniformOutput',false));
Do you see the red arrow? The last closing parenthesis is too much. Delete it.
NS
NS le 7 Jan 2019
Modifié(e) : NS le 7 Jan 2019
Class of 8th column is double.
Sir after deleting the last bracket , i am still getting this error-
[idx1] = cellfun(@(x)abs(x - mean(x)) > 3*std(x),A(:,8),'UniformOutput',false);
Index exceeds matrix dimensions.
Jan
Jan le 7 Jan 2019
Modifié(e) : Jan le 7 Jan 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?
Please save A into a .mat file and attach it with the paper clip icon so we can solve this and quit guessing.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Question posée :

NS
le 7 Jan 2019

Commenté :

le 8 Jan 2019

Community Treasure Hunt

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

Start Hunting!

Translated by