How can I delete/extract rows from a table with cell columns consisting of str and numeric values

1 回表示 (過去 30 日間)
I have a table comprising of number and cell columns:
From this table I would like to extract all rows which have "pits" in a cell in column 3 / Type.
My approaches so far:
1. Extract it via "strfind"
Ppits=P(cellfun(@isempty, strfind(P.Type, 'pits')), :);
Error:
Error using strfind
Cell must be a cell array of character vectors.
2. Delete rows with "0" or []. All attempts like logical indexing didn't work due to the fact that it's a table or the column has numerical and str values.
e.g.
>> toDelete = P < 6;
P(toDelete,:) = [];
Undefined operator '<' for input arguments of type 'table'.
  1 件のコメント
Peter Perkins
Peter Perkins 2017 年 7 月 18 日
Change the zeros to ''. Those elements will become undefined categorical values.

サインインしてコメントする。

回答 (1 件)

dbmn
dbmn 2017 年 7 月 14 日
The easiest way to extract the "pits" is to do the following
% Convert your column type to a format called categorical
% This format is supported by the table format
P.Type = categorical(P.Type)
% Then you can compare it like you would with numbers
P(P.Type == 'pits', :)
if you want to do the same with f.ex PH value just use
P(P.pH < 7, :)
and combine the two as you like
  1 件のコメント
Peter Jaenicke
Peter Jaenicke 2017 年 7 月 14 日
First of all, thank you for your answer. Using
P.Type = categorical(P.Type)
results into
Error using categorical (line 347)
Could not find unique values in DATA using the UNIQUE function.
Caused by:
Error using cell/unique (line 85)
Input A must be a cell array of character vectors.

サインインしてコメントする。

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by