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

3 visualizzazioni (ultimi 30 giorni)
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 Commenti

Accedi per commentare.

Risposta accettata

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

Più risposte (1)

Lisandro Jimenez
Lisandro Jimenez il 6 Giu 2014
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.

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by