how to use function as an input to other function ?

1 次查看(过去 30 天)
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