Add output of a function to a struct without deleting the previous struct

3 次查看(过去 30 天)
Hello, i want to call a function twice with different input and store both outputs inside the same struct. The output of the first call shall not be replaced, i need both outputs inside the struct.
Function:
function [Test1] = Test(A)
if A==2
B=A*2;
Test1.B1=B;
else
B=A*3;
Test1.B2=B;
end
end
Skript:
[Test1]=Test(2);
[Test1]=Test(3);
Like this, the second part ([Test1]=Test(3)) replaces the output of the first part.
I will greatly appreciate any assistance.
  1 个评论
Max Bornemann
Max Bornemann 2019-3-16
I just found the solution:
The struct has to be called in Output & Input!
Function:
function [Test1] = Test(Test1,A)
if A==2
B=A*2;
Test1.B1=B;
else
B=A*3;
Test1.B2=B;
end
end
Skript:
[Test1]=Test(Test1,2);
[Test1]=Test(Test1,3);

请先登录,再进行评论。

回答(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