开发者

MATLAB: simultaneously append to multiple elements of a cell array

开发者 https://www.devze.com 2023-02-17 06:12 出处:网络
I want开发者_开发问答 to append an item to multiple elements of a cell array, at once, in a loop over the items (to be appended).E.g.

I want开发者_开发问答 to append an item to multiple elements of a cell array, at once, in a loop over the items (to be appended). E.g.

nodes(nodesHere,1) = cellfun(@(x)[x items(i)], nodes(nodesHere,1),'UniformOutput',false);

The elements of nodes might be any array type.

Is there an equivalent way, relying only on indexing, rather than the relatively more expensive closure used above?


Do you mean something like

x = cell(1,5);
x(1:3) = num2cell([1, 2, 3]);
disp(x);

I know the code won't work for ANY type of array, but it would do the trick if you use mostly numeric data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号