필터 지우기
필터 지우기

When a structure is passed to a function, can we add a field to it?

조회 수: 7 (최근 30일)
As the title suggests:
If I passed a structure variable to a function, can this function add a new field to it and have that stucture among its outputs with the new added field?
Or, do I have to create a new output structure?

채택된 답변

Voss
Voss 2022년 1월 20일
편집: Voss 2022년 1월 20일
The answer is yes, the function can add a new field and pass the struct back out, and no, you don't have to create a new struct (MATLAB creates a new struct for you).
input = struct('old_field',1);
output = test_function(input);
disp(input);
old_field: 1
disp(output);
old_field: 1 new_field: 2
function in = test_function(in)
in.new_field = 2;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by