Was struct2array removed from MATLAB?

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?

Réponses (1)

dpb
dpb le 12 Mai 2022
Modifié(e) : dpb le 12 Mai 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
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 commentaires

I don't believe struct2array has ever been part of MATLAB itself, but it still exists. I believe it is installed if you install either Signal Processing Toolbox or maybe DSP System Toolbox, but I'm not 100% certain. You can see that it's available in the functionality MATLAB Answers uses to execute answer code, and that both Signal Processing Toolbox and DSP System Toolbox are available.
which -all struct2array
/MATLAB/toolbox/shared/measure/struct2array.m
ver signal
----------------------------------------------------------------------------------------------------- MATLAB Version: 9.12.0.1952421 (R2022a) Update 1 MATLAB License Number: Operating System: Linux 5.4.185-0504185-generic #202203160950 SMP Wed Mar 16 14:00:16 UTC 2022 x86_64 Java Version: Java 1.8.0_292-b10 with AdoptOpenJDK OpenJDK 64-Bit Server VM mixed mode ----------------------------------------------------------------------------------------------------- Signal Processing Toolbox Version 9.0 (R2022a)
ver dsp
----------------------------------------------------------------------------------------------------- MATLAB Version: 9.12.0.1952421 (R2022a) Update 1 MATLAB License Number: Operating System: Linux 5.4.185-0504185-generic #202203160950 SMP Wed Mar 16 14:00:16 UTC 2022 x86_64 Java Version: Java 1.8.0_292-b10 with AdoptOpenJDK OpenJDK 64-Bit Server VM mixed mode ----------------------------------------------------------------------------------------------------- DSP System Toolbox Version 9.14 (R2022a)
dpb
dpb le 12 Mai 2022
I didn't think to try with the current online facility, but searched the documentation instead, Steven. It appears undocumented other than the internal help line would still display I suppose.
This may always have been the case in that it was apparently built for some specialized purpose for the toolboxees and so never widely considred as "real" functionality but somewhat above being made private.
It's got to be a mess trying to keep all the myriad of such little specialty tools in synch and not duplicate them unnecessarily; hence the shared location it would appear.
Greg
Greg le 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 le 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.

Connectez-vous pour commenter.

Catégories

Produits

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by