gpt4 book ai didi

matlab - 创建和初始化元胞数组

转载 作者:太空宇宙 更新时间:2023-11-03 19:55:29 25 4
gpt4 key购买 nike

我正在寻找一种合适的方法来创建和初始化具有给定值的元胞数组。我能想到下面的oneliner

val = 'hello';
dim = [2, 4, 6];
arrayfun(@(x) val, zeros(dim), 'UniformOutput', false)

但我觉得很脏。

最佳答案

如果你想避免arrayfun,你可以这样做

C = cell(dim);
C(:) = {val};

C = cell(dim);
[C{:}] = deal(val);

关于matlab - 创建和初始化元胞数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26282059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com