# Direct access of structure fields returned by a function call

This code was working fine when I asked about it in Filter is too large but when I tried it again on another PC it gives me this error:

 Warning: Direct access of structure fields returned by a function call (e.g.,
call to Untitled2) is not allowed. See MATLAB 7.10 Release Notes, "Subscripting      Into     Function Return Values" for details.
??? Attempt to reference field of non-structure array.


This forwarded me to help about "Subscripting Into Function Return Values", where if you have a function, such as the following, that returns a struct array:

function structOut = getStruct
structOut = struct('fieldA', 5, 'fieldB', 10);


It is no longer valid to access fields of the structure by directly dot indexing the function's return value, as shown here:

getStruct.fieldA


Instead, you should first assign the returned structure to a variable, and then dot index the variable:

s = getStruct;
s.fieldA
ans =
5


But how can I apply it to multiply values?

• Storing the returned structure values in an array and then using the array index to refer to individual values for multiplication should work. Alternatively, you can simply use ()to enclose your multiplication variable which appears to be a field in a structure and then proceed with vector multiplication. (s.fieldA).*(s.fieldB) would be an example. – Naresh Jun 10 '13 at 7:00