how to create used input struct names

조회 수: 4 (최근 30일)
Happy PhD
Happy PhD 2020년 4월 29일
답변: Geoff Hayes 2020년 4월 29일
Hi. I created a struct,
data = struct()
I would like to add fields to it based on user input from app designer.
For example user writes a number '125' as input, then I want to create field called 'laserDist123mm' and add it to data struct.
data.laserDist123mm = 199;
equal to something.
is there any way to do this?
I want to add the new fields dynamically...

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 4월 29일
You could use setfield as
data = setfield(data, 'laserDist123mm', 199)
or as you have shown
data.laserDist123mm = 199;
which will add the field dynamically to the structure.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by