how to use function as an input to other function ?

조회 수: 1 (최근 30일)
tomer polsky
tomer polsky 2019년 3월 7일
댓글: tomer polsky 2019년 3월 10일
in my code I want to make 1 function that stores all the values of my circuit and in the other function to run simulink simultaion , my questio is simple is there a wat to insert output of function in a new function as input of the function insted of writing those varibles ?
for exmaple this my 1 function
function [U,R,R1,Duty_Cycle,C,R_C,C1,R_C1,L1,R_L1,L2,R_L2,V_diode,f,T] =Simulink_values()
U=12;
R=100;
R1=0.1;
Duty_Cycle=50;
C=1000e-6;
R_C=eps;
C1=820e-6;
R_C1=eps;
L1=330e-6;
R_L1=eps;
L2=330e-6;
R_L2=eps;
V_diode=eps;
f=18e3;
T=1/f;
end
and in my second function to write like this :
[t,I_C1] = simulink_results(Simulink_values);
insted of wrting like this :
[t,I_C1] = simulink_results(U,R,R1,Duty_Cycle,C,R_C,C1,R_C1,L1,R_L1,L2,R_L2,V_diode,f,T);

채택된 답변

CP
CP 2019년 3월 7일
The simplest way to combine outputs into a single "variable" is to use a structure. Thus, your first function and second function call would look something like this.
[simulink_values_out] = function simulink_values()
simulink_values_out.U=12;
simulink_values_out.R=100;
simulink_values_out.R1=0.1;
% and so on
end
And your second function call
[t,I_C1] = simulink_results(simulink_values_out);
You will need to change the variable names in simulink_results to match the structure notation in simulink_values.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by