Was struct2array removed from MATLAB?

188 次查看(过去 30 天)
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?

回答(1 个)

dpb
dpb 2022-5-12
编辑:dpb 2022-5-12
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
C:\ML_R2020b\toolbox\shared\measure\struct2array.m
>> 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{:}];
>>
  4 个评论
Greg
Greg 2024-3-26
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 2024-3-27
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by