Problem adding a field to a struct via function

14 ビュー (過去 30 日間)
Florian Spicher
Florian Spicher 2021 年 11 月 17 日
コメント済み: Florian Spicher 2021 年 11 月 17 日
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)
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)
and then call it via:
MeshInfo = generateTriangleCount(MeshInfo);
  1 件のコメント
Florian Spicher
Florian Spicher 2021 年 11 月 17 日
I apparently was overthinking it. Thank you :)


その他の回答 (0 件)


Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by