Pre-allocating cell array of anonymous functions
2 次查看(过去 30 天)
显示 更早的评论
Hi
I would apricate if someone can help me how to pre-allocate a cell array of anonymous functions that is later defined in a for loop. I do not what to run the loop backwards.
The for loop below exemplify what I want to do:
for q=1:q_tot
my_fun_array{q}=@(x)x^q;
end
best regard
Thomas
0 个评论
采纳的回答
Rik
2023-5-25
You can pre-allocate the cell array itself, but the contents will have to be set in the loop itself:
my_fun_array = cell(1,q_tot);
for q=1:q_tot
my_fun_array{q} = @(x)x^q;
end
Just an extra note: if you are planning to allow array inputs, you may want to use .^ instead.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!