How to use a data from time series (e.g.) in ode function?
3 次查看(过去 30 天)
显示 更早的评论
Hi, i want to use data from another mat file which contains a timeseries, below is a simplified example:
tspan = [0 5];
y0 = 0;
tQ = linspace(0,5,25);
Qg = load('GasFlowRate_T.mat', 'Qg');
[t y] = ode45(@(t,y) f(t,y,tQ,Qg),tspan,y0);
plot(t,y)
function dydt = f(t,y,tQ,Qg)
Qg = interp1(tQ, Qg, t);
dydt = Qg*t;
end
and i will get the error:
Error using interp1>reshapeValuesV (line 439)
Values V must be of type double or single.
Error in interp1>reshapeAndSortXandV (line 419)
[V,orig_size_v] = reshapeValuesV(V);
Error in interp1 (line 93)
[X,V,orig_size_v] = reshapeAndSortXandV(varargin{1},varargin{2});
but i also couldn't convert from struct to double, how could i exactly to use the data from timeseries?
0 个评论
回答(1 个)
Stephen23
2020-2-20
You just need to get the numeric array out of the structure, e.g.:
S = load('GasFlowRate_T.mat', 'Qg');
Qg = S.Qg;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!