Adding fields of two different structs together
이전 댓글 표시
% Example structures:
part(1) = struct('name', 'x', 'number', 1);
part(2) = struct('name', 'y', 'number', 2);
part(3) = struct('name', 'z', 'number', 3);
% Example: 1st user input should be the 'name' so "x"
% 2nd user input should be another'name' so "z"
% total_number = 1 + 3
댓글 수: 3
part(1) = struct('name', 'x', 'number', 1)
part(2) = struct('name', 'y', 'number', 2);
part(3) = struct('name', 'z', 'number', 3);
part(1).number+part(3).number
" is there a way to make it depend on the user's input?"
part = struct("x",1,"y",2,"z",3);
part.("x")+part.("z")
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!