Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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 Kommentar
Max Bornemann
Max Bornemann am 16 Mär. 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);

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by