MATLAB Answers

Rooy
0

Delete rows with NaN for a cell array

Rooy
さんによって質問されました 2013 年 6 月 26 日
I want to remove the rows that have NaN and still keep the dimension of the array intact.
[ NaN] [ NaN] [ NaN] [ NaN]
[ NaN] [ NaN] [ NaN] [ NaN]
'Total RADIO Drops' 'Total Drops' 'CC DCR (%)' 'RADIO DCR (%)'
Above is just an example, I have over a thousand rows.
The only problem I have now is removing rows which have NaN and string together
Thank you

  1 件のコメント

Rooy
2013 年 6 月 26 日
Is there a way to delete the rows which have strings and Nan mixed together ?
[ 'A'] [ NaN] [ NaN] [ NaN]
'Total RADIO Drops' 'Total Drops' 'CC DCR (%)' 'RADIO DCR (%)'

サインイン to comment.

2 件の回答

Tom
回答者: Tom
2013 年 6 月 26 日
 採用された回答

A(any(cellfun(@(x) any(isnan(x)),A),2),:) = [];

  1 件のコメント

Rooy
2013 年 6 月 26 日
Thank you, it works

サインイン to comment.


Andrei Bobrov
回答者: Andrei Bobrov
2013 年 6 月 26 日
編集済み: Andrei Bobrov
2013 年 6 月 26 日

A - your cell array
out = A(any(cellfun(@(x)any(~isnan(x)),A),2),:);
ADD
out = A(all(cellfun(@(x)any(~isnan(x)),A),2),:);

  3 件のコメント

Rooy
2013 年 6 月 26 日
That works thank you, is there a way to delete the rows which have strings and Nan mixed together ?
Andrei Bobrov
2013 年 6 月 26 日
see ADD part in my answer
Rooy
2013 年 6 月 26 日
Thank you for your great help

サインイン to comment.



Translated by