Analog VBA statement "with ... end with"

1 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by