Effacer les filtres
Effacer les filtres

Analog VBA statement "with ... end with"

1 vue (au cours des 30 derniers jours)
Sergey Kasyanov
Sergey Kasyanov le 20 Fév 2017
I need declare a lot (real many) fields of structure with long name. How i can do it without using loop?
For example:
Horrible version:
VeryVeryLongAndInappropriateNameOfStructurOrInstanceOfClass.FirstField=1;
VeryVeryLongAndInappropriateNameOfStructurOrInstanceOfClass.FirstField.AnotherFiled=2;
VeryVeryLongAndInappropriateNameOfStructurOrInstanceOfClass.SecondField=3;
repeat while your beard grow and becoming white;
Pretty version (what i need):
MagicStatement(VeryVeryLongAndBoringNameOfStructurOrInstanceOfClass)
FirstField=1;
FirstField.AnotherField=2;
Real version (what i using now):
VeryVeryLongAndBoringNameOfStructurOrInstanceOfClass=struct();
NameOfFields={FirstField,SecondField,...};
ValueOfField={1,'value',...};
for i=1:length(NameOfFields)
VeryVeryLongAndBoringNameOfStructurOrInstanceOfClass.(NameOfFields{i})=ValueOfFields{i};
end
First and last versions are hard to read and understand. Can I implement second version in MATLAB?

Réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by