How Can I store results from Variable step solver(ODE15s) to a Pre-initialized variable

2 views (last 30 days)
Hello All, I have been working on a problem which using ODE15s solver and anonymous function . I have used Coder.extrinsic(myfunction) in my MATLAB code in order to avoid issues while codegen. So I need to pre-Initialize a variable to store results from myfunction. My Coder.extrinsic(myfunction) has following code.
[T,Y] = ode15s(@(t,y) fn_diffeq(t,y,a,b,b,d,e,f,g,h,i,j), [0,time],k);
The size of Y will change according to input conditions to ODE15s Solver. it might be 100x40 for first iteration, 200x40 for second iteration and 10x40 for third iteration and etc.
I am looking for a way to Pre-initialize a variable to store this result vector.
Can Someone please help me to figure out a way to implement this problem.
Thanks in advance. Easwar

Accepted Answer

Easwar Kumar Yarrabikki
Easwar Kumar Yarrabikki on 20 Jan 2017
Edited: Easwar Kumar Yarrabikki on 20 Jan 2017
First Initialized Vector Y as Y=zeros(100x48). Also introduced Coder.varsize('Y',[1000 48],[1 0]). Coder.varsize will allow Y to change its size according to result during simulation. It does worked out for me. for more details on to use coder.varsize look at coder.varsize

More Answers (0)

Community Treasure Hunt

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

Start Hunting!