フィルターのクリア

Remove rows using Cellfun satisfying customised function

5 ビュー (過去 30 日間)
NS
NS 2019 年 1 月 7 日
コメント済み: Image Analyst 2019 年 1 月 8 日
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 件のコメント
Jan
Jan 2019 年 1 月 7 日
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 2019 年 1 月 7 日
Sorry for confusion, yes i am getting one error , i have updated the code and error.

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2019 年 1 月 7 日
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 件のコメント
Jan
Jan 2019 年 1 月 7 日
編集済み: Jan 2019 年 1 月 7 日
@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 2019 年 1 月 8 日
Please save A into a .mat file and attach it with the paper clip icon so we can solve this and quit guessing.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by