Problem adding a field to a struct via function

조회 수: 6 (최근 30일)
Florian Spicher
Florian Spicher 2021년 11월 17일
댓글: Florian Spicher 2021년 11월 17일
Hi!
I would like to use functions, which compute a few things, and then add the respective results to my struct. My problem is that, when I put the very same lines in the command window, it works perfectly, but when I use my functions, nothing changes.
For example, I have the short code:
function generateTriangleCount(MeshInfo)
SizeTriangleField=size(MeshInfo.tri);
MeshInfo.NT=SizeTriangleField(1);
end
where MeshInfo is my structure. Entering generateTriangleCount(MeshInfo) does not add the field NT to my structure, but entering SizeTriangleField=size(MeshInfo.tri); and MeshInfo.NT=SizeTriangleField(1); does. What do I do wrong?

채택된 답변

Kelly Kearney
Kelly Kearney 2021년 11월 17일
Your function doesn't return any output. Modify it to do so:
function MeshInfo = generateTriangleCount(MeshInfo)
SizeTriangleField=size(MeshInfo.tri);
MeshInfo.NT=SizeTriangleField(1);
end
and then call it via:
MeshInfo = generateTriangleCount(MeshInfo);

추가 답변 (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