isfield — Test whether structure metadata contains one or more field names.
isfield returns scalar or same-shaped logical results for exact, case-sensitive field-name queries without reading stored values.
Syntax
tf = isfield(S, name)Inputs
S- Type
Any- Required
- Yes
- Description
- Value whose structure metadata is queried.
name- Type
Any- Required
- Yes
- Description
- Character row, string value, string array, or cell collection of names.
Returns
tf- Type
LogicalArray- Description
- Logical result matching the field-name query shape.
Errors
RunMat:isfield:TooManyOutputs- When
- More than one output is requested.
- Message
isfield: too many output arguments
RunMat:isfield:FieldNameType- When
- Field-name input is not a string scalar, string array, character row, or cell collection of scalar text.
- Message
isfield: field names must be strings, string arrays, or cell arrays of character vectors
RunMat:isfield:CellElementType- When
- A field-name cell element is not scalar string or character-row text.
- Message
isfield: cell array elements must be character vectors or strings
RunMat:isfield:InternalError- When
- Logical result construction fails.
- Message
isfield: internal error
Queries and results
isfield(S,name) compares field names exactly and case-sensitively. A character row or scalar string produces one logical scalar. A string array or cell collection of scalar text produces a logical array with the query collection's shape.
If S is not a structure, the result is false with the same scalar or array form. Unsupported field-name values reject instead of converting numbers or other values to text.
Structure arrays
A structure array has one ordered field schema shared by every element, so a queried name is either present for the complete array or absent. Empty structure arrays retain this schema.
Ordinary cell arrays remain non-structure inputs even when every cell happens to contain a scalar structure.
Residency and execution
isfield reads outer host-side metadata only. It does not inspect, copy, or gather values stored in a structure, launches no accelerator kernel, and forms a fusion boundary.
Examples
Test one field name
s = struct('name', 'entry', 'score', 42);
hasScore = isfield(s, 'score')Expected output:
hasScore = trueTest a shaped cell of names
s = struct('name', 'entry', 'score', 42);
names = {'name', 'department'; 'score', 'email'};
mask = isfield(s, names)Expected output:
mask = logical [1 0; 1 0]Query a structure array
entries = struct('name', {'first', 'second'}, 'id', {101, 102});
mask = isfield(entries, ["id", "department"])Expected output:
mask = logical [1 0]Initialize an optional field
cfg = struct('mode', 'fast');
if ~isfield(cfg, 'rate')
cfg.rate = 60;
endExpected output:
cfg.rate = 60Mix string and character names
opts = struct('Solver', 'cg', 'MaxIter', 200);
queries = {"Solver", 'Tolerances'; 'MaxIter', "History"};
present = isfield(opts, queries)Expected output:
present = logical [1 0; 1 0]Query a non-structure value
value = 42;
tf = isfield(value, 'anything')Expected output:
tf = falseUsing isfield with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isfield changes the result.
Run a small isfield example, explain the result, then change one input and compare the output.
FAQ
Which field-name inputs are accepted?⌄
Character rows, scalar strings, string arrays, and cell arrays whose elements are character rows or scalar strings.
What happens when the first input is not a structure?⌄
The result is false, or a same-shaped logical array of false values. Use isstruct when the value's class must be checked separately.
How are structure arrays queried?⌄
The query is checked against the array's shared field schema.
What happens for an empty structure array?⌄
The query is checked against the field schema retained by the empty array.
Are comparisons case-sensitive?⌄
Yes. Names must match exactly, including case.
Does isfield gather GPU data?⌄
No. Nested resident values remain with their provider because only outer metadata is read.
Related Structs functions
fieldnames · getfield · orderfields · rmfield · setfield · struct · structfun
Source you can read
Every RunMat function's source is public. Read exactly how isfield is executed, line by line, in Rust.
- View the source for isfield in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.