rmfieldRemoving field from structure
rmfield(S, field)S should be a structure array of any size.field should be a vector of characters.S with the field field removed.S is unaltered after the execution of the function.| MATLAB | SIMO |
|---|---|
field can be a cell array, so that multiple fields can be removed in one function call | Cell array not supported |
field can be a string | String not supported. Use character array instead. |
| Remove one or more fields in one function call | Remove just one field in one function call |
owner, manufacturer and electric. Then, we obtain a new structure by removing the field electric from all elements of cars. Note that the original array car was not modified by the function refield.% 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')
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