Remove columns of cell that contain double

2 ビュー (過去 30 日間)
RuiQi
RuiQi 2016 年 7 月 12 日
編集済み: the cyclist 2016 年 7 月 12 日
I am aware that I can use http://www.mathworks.com/help/matlab/ref/isa.html to determine the data type of an object. However, how would I find the data type of the columns of a cell ? I need to remove the cells that are of not type double. For example, I have tried
isa(result{:},'double')
isa(result,'double')
to find out if the columns are of type double and it has not worked. I decided to just use a for loop to find the columns that contain double/single. Given this new data keep where keep(i) = 1 if column i contains single and 0 if column i contains double, how do i remove the columns that contain doubles ?

回答 (2 件)

the cyclist
the cyclist 2016 年 7 月 12 日
編集済み: the cyclist 2016 年 7 月 12 日
Use the cellfun function to apply a function to each cell of a cell array. For example,
C = {[1 2 3],'a'};
removeIdx = not(cellfun(@(x)isa(x,'double'),C));
C(removeIdx) = [];

KSSV
KSSV 2016 年 7 月 12 日
C = {1:10, [2; 4; 6], ['cool']}; % A cell array
types = cellfun(@class, C,'UniformOutput', false) ; % get the classes of each cell
IndexC = strfind(types, 'double'); % get the indices of doubles
Index = find(not(cellfun('isempty', IndexC)));
iwant = C(Index) % pick only doubles

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by