필터 지우기
필터 지우기

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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by