Clear Filters
Clear Filters

Was struct2array removed from MATLAB?

188 views (last 30 days)
Mark Lepage
Mark Lepage on 12 May 2022
Commented: Star Strider on 27 Mar 2024
I am using a newish program, but I am getting the error:
Unrecognized function or variable 'struct2array'.
I remember using this in the past, but appears to longer be a part of MATLAB?

Answers (1)

dpb on 12 May 2022
Edited: dpb on 12 May 2022
struct2cell seems to be lowest level still extant, yes. <struct2array#answer_403725> gives some history(*) of its evolution from the Signal Processing Toolbox to main product to now apparently red-haired stepchild.
I suppose that since a struct isn't required to be directly convertible to an array given the different field content possible, TMW decided it wasn't a generally-enough-applicable function to keep so they abandoned it.
(*) I don't know when I've used it, if ever; I also tend to avoid struct when can, generally using the table for heterogenous data instead, so hadn't ever noticed anything about it.
I'm still using R2020b here; there it is still extant, but the doc page is just the help text one-liner. I dunno, that may have been the extent always on that...
>> which -all struct2array
>> which -all struct2cell
built-in (C:\ML_R2020b\toolbox\matlab\datatypes\@struct\struct2cell) % struct method
All struct2array is is the catenation of the output from struct2cell into an array -- which may/may not always work...
>> type struct2array
function a = struct2array(s)
%STRUCT2ARRAY Convert structure with doubles to an array.
...dpb snip...
% Convert structure to cell
c = struct2cell(s);
% Construct an array
a = [c{:}];
Greg on 26 Mar 2024
I just discovered this myself. I have two different machines, both running R2024a. My code that calls struct2array runs perfectly fine in one, and not the other. The other has no doc installed, and a trimmed list of installed toolboxes. I tried to use license inuse on the working machine, but apparently even though it comes from a toolbox (either Signal Processing or Digital Signal Processing as mentioned elsewhere), it does not consume a license for said toolbox. This makes it very difficult to track down. And now I have a toolbox dependency, but not a license dependency?
Star Strider
Star Strider on 27 Mar 2024
I can’t find struct2array in the online documentation (that lists absolutely everything), or in an Interweb search.
I don’t use structures very often, however a workaround could be to combine struct2table and table2array, perhaps in your own ‘struct2array’ function.

Sign in to comment.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!