필터 지우기
필터 지우기

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 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