2
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Ertxiem Sep 18 at 15:10
  • $\begingroup$ I can accept my answer in 20 hours. $\endgroup$ – Alex Sep 19 at 16:37
0
$\begingroup$

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);
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Ertxiem Sep 19 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.