how to recognize if an element of a cell array is a char vector

6 ビュー (過去 30 日間)
Umberto Filippi
Umberto Filippi 2021 年 8 月 17 日
コメント済み: Umberto Filippi 2021 年 8 月 17 日
Good morning to everyone,
I am writing a code which takes all the 'n' variable inputs (varargin) and creates a (n/2)x2 cell array. It Is a name value pair function, so input arguments are coming in pairs.
Since the first column must contain only name, I have to check that they are not number, and return and empty cell array if they are.
Unfortunately the ischar or isnumeric commands are not working since varargin() with () indices gives a cell array and ischar is false for cell array.
An example is C = name_value_pairs('name', 'John Smith', 'age', 32, 'children', {'Bill' 'Cloe'})
C =
3×2 cell array
{'name' } {'John Smith'}
{'age' } {[ 32]}
{'children'} {1×2 cell }
But with C = name_value_pairs('name', 'John Smith', 34, 32, 'children', {'Bill' 'Cloe'}), I Should obtain an empty C.
Can anyone help me please?

採用された回答

Yazan
Yazan 2021 年 8 月 17 日
c = {'name', 'John Smith'; 'age', 32; 'children', cell(1,2)}
c = 3×2 cell array
{'name' } {'John Smith'} {'age' } {[ 32]} {'children'} {1×2 cell }
cellfun(@ischar, c)
ans = 3×2 logical array
1 1 1 0 1 0

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by