Using function handles and indexing on cells, Error: Undefined function 'eq' for input arguments of type 'cell'.
Mostrar comentarios más antiguos
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 comentarios
Cathleen Turner
el 26 de Jun. de 2013
Cathleen Turner
el 26 de Jun. de 2013
Editada: Cathleen Turner
el 26 de Jun. de 2013
Respuestas (1)
Walter Roberson
el 26 de Jun. de 2013
My guess is that you want
fh1 = @(x) any(isnan(x(:)));
and that for whereNaN_DO you want to use uniform true
4 comentarios
Cathleen Turner
el 26 de Jun. de 2013
Editada: Cathleen Turner
el 26 de Jun. de 2013
Tom
el 26 de Jun. de 2013
x isn't used anywhere in that anonymous function?
Cathleen Turner
el 26 de Jun. de 2013
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...
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!