필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Max Bornemann
Max Bornemann 2019년 3월 16일
편집: madhan ravi 2019년 3월 16일
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