User`s guide

R14SP2
24-12
x = 10;
x.name = magic(3);
Warning: Struct field assignment overwrites a value with class
"double".
In a future release of MATLAB, attempting this type of operation will throw an error
instead of just displaying a warning message.
Compatibility Considerations
You are encouraged to modify any code that generates this warning. The section “Making
a Valid Assignment” on page 24-12 gives instructions on how to do this.
Another Case — Extending the Depth of a Structure
The same rules apply when extending the depth of a structure by adding additional,
lower-level fields. The first line of the example shown below creates a structure named
handle and assigns to it a field of type double named output. The line after that treats
this double as if it were a structure by attempting to assign a field named time to it. The
second line is an invalid expression:
handle.output = 5;
handle.output.time = 13;
As in the case discussed earlier, this assignment does not generate a warning or error in
MATLAB releases prior to R14. In the R14 and R14 service pack releases of MATLAB,
you get the warning shown in the previous example. Beginning in a future release of
MATLAB, this assignment will throw an error.
Making a Valid Assignment
To avoid this warning and future errors, first make x an empty structure or empty array
as shown here. Once a variable is established as a structure or empty array, you can
assign fields to it without getting an error:
x = struct; or x = [];
x.name = magic(3);
In the case of extending the depth of an existing structure, you can perform this type of
assignment without generating a warning or error using the struct function as shown
here: