equivalent of isfield for tables
이전 댓글 표시
I'd like to know if my Matlab table has a particular column. If it was a structure I'd use isfield. Is there a built in function for this?
채택된 답변
추가 답변 (1개)
Roger Parkyn
2015년 9월 15일
편집: Roger Parkyn
2015년 9월 15일
This issue was also raised by Pawel Kusmierek ( 123242-why-isfield-does-not-work-with-tables-but-fieldnames-does ). He gave a reasonably tidy work-around, in short:
name_exists = any(strcmp('Var_Name',fieldnames(Table_Name)))
댓글 수: 1
Kelly Kearney
2015년 9월 15일
Note that fieldnames returns all object properties, which for a table includes both variable names and the Properties structure. To get just the column/variable names, query the VariableNames property:
t = table({'one';'two'}, [1;2])
t =
Var1 Var2
_____ ____
'one' 1
'two' 2
>> t.Properties.VariableNames
ans =
'Var1' 'Var2'
>> fieldnames(t)
ans =
'Var1'
'Var2'
'Properties'
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!