# Passing data as arguments in ODE45

I need to import data from file in order to describe the structure of a network. I used the following:

weights = readtable('weights192.txt');
W = weights{:,:};


Now, I need to use matrix W (its elements, its size) in the function ode below. How can I pass the matrix or just the elements I need in terms of arguments in the ode45, in order for my function to have access to it?

time = 0:0.01:5;
y0 = zeros(16,1);
[t,y] = ode45(@ode,time,y0);

function [dydt] = ode(t,y)
...
end


Alternatively, is it possible to import the matrix and its data directly in the function? Although for practical reasons of code structure, I would prefer to choose the structure of my network, outside the function.

• If you want, you may post the new part of the post as an answer to your own question and then accept it. This way, the question will not remain open. – Ertxiem - reinstate Monica Sep 18 '19 at 15:10
• I can accept my answer in 20 hours. – axel Sep 19 '19 at 16:37

I figured that a possible way to pass data relevant to the differential equation or dynamical system one may want to solve, and which is not initial conditions or time span, is to use this format:

[t,y] = ode45(@(t,y) ode(t,y,parameter_1,parameter_2,parameter_3,...), time, y0);

• I'm not the downvoter, but I suggest that you edit your answer and provide some explanation why the code provides an answer to the question. – Ertxiem - reinstate Monica Sep 19 '19 at 23:11