Using function handles and indexing on cells, Error: Undefined function 'eq' for input arguments of type 'cell'.

조회 수: 1 (최근 30일)
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!
  댓글 수: 2
Cathleen Turner
Cathleen Turner 2013년 6월 26일
To clarify what I need to do...
if I were to do this in a for loop I would add:
mat1=cell2mat(whereNaN_Flag_DO);
mat2=cell2mat(whereNaN_DO);
itrs=size(Flag_DO);
itrs=max(itrs);
itrs=size(Flag_DO);
itrs=max(itrs);
for gg=1:itrs
if mat1(gg) ==0 | mat2(gg) ==0
Store{gg}=Flag_DO{gg}
end
end
I don't like this method because 1) it despairs data by giving each string its own cell, and creates many many columns 2) I want to do it using indexing. If 2 isn't feasible how can fix the problem with 1)?
Cathleen Turner
Cathleen Turner 2013년 6월 26일
편집: Cathleen Turner 2013년 6월 26일
edit 2:
to give you an idea of what the error dataset is like
Flag_DO{1:2}
ans =
<0>
ans =
<0>[GFT]
the problem with the forloop is that it would separate the second answer into 2 columns and I end up having many many columns

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
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
Cathleen Turner 2013년 6월 26일
Oh I thought that you had to write a function handle with x by default then use it for cell function. Was I wrong?
Tom
Tom 2013년 6월 26일
편집: Tom 2013년 6월 26일
It works similar to a standard function - if you don't need any input arguments (which is a bit unusual), then you'd write it as @() stuff.... ; if you need to arguments (say for a uicontrol callback), you could write @(hObject,eventData) stuff...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by