[TOC]

rmfield

Removing field from structure

Usage

rmfield(S, field)

Difference with MATLAB

MATLABSIMO
field can be a cell array, so that multiple fields can be removed in one function callCell array not supported
field can be a stringString not supported. Use character array instead.
Remove one or more fields in one function callRemove just one field in one function call

Example

Input
% Car 1
car(1).owner = 'marc';
car(1).manufacturer = 'mazda';
car(1).electric = false;

% Car 2
car(2).owner = 'jane';
car(2).manufacturer = 'tesla';
car(2).electric = true;

% Car 3
car(3).owner = 'bob';
car(3).manufacturer = 'bmw';
car(3).electric = false;

% Print out the structure array
car

% Remove the field electric.

disp('After removing the field')
car_copy = rmfield(car,'electric')
Output
car =
 struct array (1 x 3) with fields:
 owner, manufacturer, electric

After removing the field

car_copy =
 struct array (1 x 3) with fields:
 owner, manufacturer