Analog VBA statement "with ... end with"
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!