You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何生成MATLAB结构体的所有可能排列组合并动态适配输入变更

MATLAB 结构体数组生成需求

我有一个MATLAB模板结构体,想要基于它生成更复杂的输出结构体。现有代码如下:

conditions = {'Listen',':=:'};
items = ["apple" "duck"]; % 2 items

stims = cellstr([ ...
    items, ... % text
    items+".PNG", ... % picture
    items+".wav" ... % sound
    ]);

event = struct( ...
    'Cue', struct('duration',2,'jitter',0.25,'shows',conditions), ...
    'Stimuli', struct('duration','sound','shows',stims), ...
    'Delay', struct('duration',2,'jitter',0.25), ...
    'Go', struct('duration',1,'jitter',0.25,'shows','Speak','skip','Cue==:=:'), ...
    'Response', struct('duration',3,'jitter',0.25,'skip','Cue==:=:'));

当前运行代码后得到的是1×1结构体:

events = 

  1×1 struct with fields:

         Cue: [1×2 struct]
     Stimuli: [1×6 struct]
       Delay: [1×1 struct]
          Go: [1×1 struct]
    Response: [1×1 struct]

我需要基于上述模板生成一个1×12的结构体数组,要求包含顶层字段的所有可能组合,示例输出如下:

events = 

  1×12 struct array with fields:

         Cue: [1×1 struct]
     Stimuli: [1×1 struct]
       Delay: [1×1 struct]
          Go: [1×1 struct]
    Response: [1×1 struct]

补充要求

输出必须能动态适配输入的变化,例如:

  • 修改event.Delay.duration = [1,2,3]时,生成的结构体数组大小应为原大小的3倍,包含所有延迟时长的可能组合;
  • 移除Cue字段时,输出结构体数组大小应为原大小的一半。

内容的提问来源于stack exchange,提问作者Aaron Earle-Richardson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 07:54:10