Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Max Bornemann
Max Bornemann il 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);

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by