フィルターのクリア

Analog VBA statement "with ... end with"

1 回表示 (過去 30 日間)
Sergey Kasyanov
Sergey Kasyanov 2017 年 2 月 20 日
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 Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by