Using function handles and indexing on cells, Error: Undefined function 'eq' for input arguments of type 'cell'.
이전 댓글 표시
Hello! Thank you for reading my question!
I have a dataset that is the following:
DO_data_and_quality =
[226051x10 double] [226051x1 double] {226051x1 cell} {226051x1 cell}
First: station name, second:datenum, third: dissolve oxygen measurements (has NaN because of missing fields due to spacing or missed measurement), fourth: error code in the form of the following:
%<<0>> {a number -5:1:5 enclosed by <<>>}
%<<0>>[ERR] {the above and a bracketed three letter error code}
%NaN {for empty cells, it came from an excel file}
Primary objective: Remove the a row that has NaN, for all of the cell objects. Secondary objective: To group the error codes into their own cells, with the corresponding row of the other cells
*Code for primary objective:
Flag_DO=NDBCdata.F_DO_mgl;
rawDO=NDBCdata.DO_mgl;
fh1 = @(x)isnan(x(:));
whereNaN_Flag_DO=cellfun(fh1, Flag_DO,'UniformOutput',false);
whereNaN_DO=cellfun(fh1, raw_DO,'UniformOutput',false); %creates a vector where 1 means that there is a NaN, 0's mean that there isn't one
% if =1 has a NaN then =0 there is no NaN, then any number besides 0 has a NaN, remove the row
raw_DO=NDBCdata.DO_mgl;
fh2=@(x)(x(whereNaN_DO ==1 | whereNaN_Flag_DO ==1));
DO_data_and_quality={ NDBCdata.ID_num NDBCdata.DateNUM raw_DO Flag_DO};
DO_data_and_quality(cellfun(fh2, DO_data_and_quality)) = [];
I am not using indexing correctly, may I have a few pointers?
Even more stangely when I click on the problem line in the error msg I get: Undefined function or variable 'whereNaN_DO'.
I did a whos whereNaN_DO and I get an output! Name Size Bytes Class Attributes
whereNaN_DO 226051x1 25543763 cell
*For secondary objective
I was going use: codeFlag_DO=cellfun(@double,Flag_DO, 'UniformOutput', false); and use a similar indexing method where I would select the second term or the last few terms if there is a 3 letter error code.
Thanks!
답변 (1개)
Walter Roberson
2013년 6월 26일
My guess is that you want
fh1 = @(x) any(isnan(x(:)));
and that for whereNaN_DO you want to use uniform true
댓글 수: 4
Cathleen Turner
2013년 6월 26일
편집: Cathleen Turner
2013년 6월 26일
Tom
2013년 6월 26일
x isn't used anywhere in that anonymous function?
Cathleen Turner
2013년 6월 26일
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!