Multiply structure by a constant
조회 수: 22 (최근 30일)
이전 댓글 표시
Like to multiply a structure with fields by a constant, but it giving an error. Is there another way to do this?
댓글 수: 0
답변 (2개)
Bora Eryilmaz
2023년 1월 12일
You have to cycle through the individual fields of the structure:
s = struct('a', [1 2 3 4], 'b', -1)
for f = fieldnames(s)'
s.(f{1}) = 4 * s.(f{1});
end
s
댓글 수: 2
Bora Eryilmaz
2023년 1월 12일
Not sure what you mean by "variable names". Are you referring to the variable name of the struct or the fields of the struct?
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!