DATASET objects have SET and GET methods defined. Please see the documentation for DATASET SET and GET methods for more information on usage.
Please also note that these methods are similar to the SET and GET methods defined for handle graphics, except for one important difference: to make a change on object OBJ, the object output from a SET command on OBJ must be reassigned to OBJ. If this reassignment is not done, the changes will not be made.
An example of changing the variable names of a dataset object for the IRIS object created above is as follows:
iris = set(iris,'VarNames',{'varname1','varname2','varname3','varname4','varname5'})
As per the reassignment discussion above, if we had executed the following, the changes would not have been made:
set(iris,'VarNames',{'varname1','varname2','varname3','varname4','varname5'})
To change only a single variable name, execute:
varnames = get(iris, 'VarNames');
varnames{3} = 'MyVarName';
iris = set(iris, 'VarNames', varnames);
You can also change a single variable name by explicitly setting this property, i.e.:
iris.Properties.VarNames{1}='newName'
Best Answer