For each non NaN value in the 2rd column, remove the entire row of Cell

raw= [UPS CALL;WMB NaN;LNG NaN; XLE PUT ;DIS CALL]
('raw' is a cell in my case)
Here is what I have so far but it does not work:
[dummy,dummy,raw] = xlsread(fullfile(source_dir,source_files(i).name));
Equity_only = cellfun(@isfinite,raw(:,2),'un',0)
raw=cell2table(raw)
raw(Equity_only,:) = []
raw = table2cell(raw);
Help please!

回答 (3 件)

Jos (10584)
Jos (10584) 2014 年 7 月 9 日
Despite raw being a cell, are there only numbers in the second column? If so:
tf = isnan(vertcat(raw{:,2})) ;
raw2 = raw(tf,:)
If not
tf = cellfun(@(E) numel(E)==1 && isnumeric(E) && isnan(E), raw(:,2))
raw2 = raw(tf,:)
(I am not sure about the "not" in your title. Perhaps you need ~tf ??)
Florent
Florent 2014 年 7 月 10 日
編集済み: Star Strider 2014 年 7 月 10 日
Thanks a lot, that really help!
tf = cellfun(@(E) numel(E)==1 && isnumeric(E) && isnan(E), raw(:,2))
raw2 = raw(tf,:)
Was what I needed!
Now, how do I do if I only want to keep rows with certain strings, for example 'CALL', as well as the NaN value (but remove rows with all other strings)?
Andrei Bobrov
Andrei Bobrov 2014 年 7 月 10 日
tf = cellfun(@(E) (numel(E)==1 && isnumeric(E) && isnan(E))...
||(all(isletter(E))&&strcmp('CALL',E)), raw(:,2));
raw2 = raw(tf,:);

カテゴリ

ヘルプ センター および File ExchangeNumeric Types についてさらに検索

質問済み:

2014 年 7 月 9 日

回答済み:

2014 年 7 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by