how to set multiple fields in a struct without using a loop

3 次查看(过去 30 天)
Hello guys, I have the next problem, I want to make something like this:
A={'A1';'A2';'A3'};
them make B=somefunction(B,A); and obtain this:
B =
A1: []
A2: []
A3: []
Any idea?
  4 个评论

请先登录,再进行评论。

采纳的回答

José-Luis
José-Luis 2014-6-6
编辑:José-Luis 2014-6-6
A = {'A1';'A2';'A3'};
your_struct = cell2struct(repmat({[]},3,1),A);
Please accept an answer if it helped you.

更多回答(1 个)

Lisandro Jimenez
Lisandro Jimenez 2014-6-6
for i=1:size(A,1)
B.(A{i})=[];
end
But this answer has a loop, and I don't know if there's another way more efficent.

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by