Clear Filters
Clear Filters

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

3 views (last 30 days)
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 Comment
Max Bornemann
Max Bornemann on 16 Mar 2019
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);

Sign in to comment.

Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!