MATLAB Answers

0

how to use function as an input to other function ?

Asked by tomer polsky on 7 Mar 2019
Latest activity Commented on by tomer polsky on 10 Mar 2019
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);

  0 Comments

Sign in to comment.

Tags

Products

1 Answer

Answer by CP
on 7 Mar 2019
 Accepted Answer

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.

  1 Comment

thank you for your help

Sign in to comment.