removing entire row in cell array if first column is a NaN
Mostrar comentarios más antiguos
My data matrix (after reading into matlab with xlsread) contains many rows of string and numerical data, and at the end, there sometimes exists several rows of "NaN"s
I want to delete these specific rows but can't seem to do it properly.
I've tried q=cellfun(@(x) all(isnan(x)),myMatrix); myMatrix(q); but the result is no longer a cell
I've tried findNan=isnan(myMatrix(:,1)) to find the index of the row containing the NaN's to kill it, but it gives an error: ??? Undefined function or method 'isnan' for input arguments of type 'cell'.
Any assistance is appreciated! Thanks :)
2 comentarios
Walter Roberson
el 6 de Jun. de 2012
xlsread() can return 3 matrices, one for numeric, one for text, one for raw. Which one are you working with? To get the mix of numeric and text you must be working with raw ?
David C
el 6 de Jun. de 2012
Respuesta aceptada
Más respuestas (1)
the cyclist
el 6 de Jun. de 2012
Does this do what you want?
% Some made-up data
c = num2cell([1 1; 2 2; NaN NaN]);
% Find the rows with all NaN
indexToRowToDrop = all(arrayfun(@(x)isnan(x{:}),c),2)
% Drop the bad rows
c(indexToRowToDrop,:) = [];
Categorías
Más información sobre Data Distribution Plots 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!