如何从另一个程序访问 MATLAB(插值)样条曲线?
如果我要从大量数据(大约 400 个图表,每个图表 500,000 个值)创建插值样条线,那么如何快速有效地从另一个软件访问这些样条线的坐标?
最初,我打算对数据进行回归,并在我的 delphi 程序中使用生成的公式,但事实证明这比我想象的更痛苦。
我目前正在使用 Matlab,但如果需要的话我可以使用其他软件。
编辑:该数据代表一些其他数据(我已经在数据库中)的经验累积分布可能是相关的。
以下是其中一张图表的外观。
重点是访问速度。我打算使用这些数据对财务数据进行模拟。
If I was to create interpolated splines from a large amount of data (about 400 charts, 500,000 values each), how could I then access the coordinates of those splines from another software quickly and efficiently?
Initially I intended to run a regression on the data and use the resulting formula in my delphi program, but that turned out to be a bigger pain than I thought.
I am currently using Matlab but I can use another software if need be.
Edit: It is probably relevant that this data represents the empirical cumulative distribution
of some other data (which I already have in a database).
Here is what one of these charts would look like.
The emphasis is on speed of access. I intend to use this data to run simulations on financial data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MATLAB 有一个用于将样条曲线转换为分段多项式的命令。然后,您可以使用
unmkpp
提取每项多项式的间断点和系数,并在另一个程序中对其求值。MATLAB has a command for converting a spline into a piecewise polynomial. You can then extract the breaks and the coefficients of each piece of polynomial with
unmkpp
, and evaluate them in another program.如果您也熟悉 C,您可以使用 Matlab 编码器或类似的东西来获取中间库,将您的 Delphi 程序和 MATLAB 连接在一起。 Delphi 和 C 代码的接口虽然有点乏味,但肯定是可能的(或者早在 Delphi 7 的时代)。或者您甚至可以在 MATLAB 中编写算法,使用 Matlab 编码器将代码转换为 C,然后从 Delphi 中调用生成的 C 库。
也许有点矫枉过正,但您可以从 MATLAB 将数据存储在数据库(例如 MySQL)中,并从 Delphi 检索它们。
最后:Delphi 是一个真正的限制吗?您还可以使用 MATLAB 进行仿真,因为您可能拥有与 Delphi 中相同(甚至更多)的可用于 MATLAB 的工具。之后您可以分享结果,我认为这对速度不太重要。
If you are also familiar with C, you could use Matlab coder or something similar to get an intermediate library to connect your Delphi program and MATLAB together. Interfacing Delphi and C code is, albeit a tad tedious, certainly possible (or it was back in the days of Delphi 7). Or you could even write the algorithm in MATLAB, convert the code to C using Matlab coder and from within Delphi call the generated C library.
Perhaps a bit overkill, but you can store your data in a database (e.g. MySQL) from MATLAB and retrieve them from Delphi.
Finally: is Delphi a real constraint? You could also use MATLAB to do the simulations, as you might have the same tools (or even more) available for MATLAB than in Delphi. Afterwards you can just share the results, which I suppose is less speed critical.
我最初的猜测是在 MATLAB 中使用
memmapfile
创建一个内存映射文件,将数据填充到查找表中,然后在 Delphi 代码中打开内存映射文件并从该文件中读取数据。My initial guess at doing this efficiently would be to create a memory mapped file in MATLAB using
memmapfile
, stuff a look-up table with your data into that, then open the memory mapped file in your Delphi code and read the data from that file.最快的很可能是保存到磁盘并在模拟代码中加载和使用的查找表(尽管:为什么不在 Matlab 中运行模拟?)
您可以评估样条以获得细粒度的值列表使用 FNVAL 计算
x
的值,并使用最接近的值x
查找 cdf。The fastest is most likely a look-up table that you save to disk and that you load and use in your simulation code (although: why not run the simulation in Matlab?)
You can evaluate the spline for a finely-grained list of values of
x
using FNVAL, and use the closest value ofx
to look up the cdf.