在MATLAB中缓存函数结果的最简洁方法 [英] Cleanest way to cache function results in MATLAB

查看:314
本文介绍了在MATLAB中缓存函数结果的最简洁方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中有一个很繁重的功能:

I have quite a heavy function in MATLAB:

function [out] = f ( in1, in2, in3)

经常使用相同的参数来调用. 该函数是确定性的,因此对于给定的输入参数,其输出将始终相同.

Which is called quite often with the same parameters. The function is deterministic so for given input parameters its output will always be the same.

将计算出的输入结果存储在函数中的最简单方法是什么,如果再次使用相同的输出调用该函数,它便能够快速回答?

What would be the simplest way of storing the results of computed inputs in the function such that if the function will be called again with the same output it would be able to answer quickly?

是一个持久变量,它(使用containers.Map或其他类)将输入集<in1, in2, in3>映射为结果吗?

Is a persistent variable which maps (using containers.Map or some other class) input set <in1, in2, in3> to a result the way to go?

请注意,任何需要将数据保存到磁盘的方法在我的应用程序中都是不可能的.

Note that any method which requires saving the data to disk is out of the question in my application.

推荐答案

MATLAB现在附带了一个仅用于此目的的函数. 使用的技术称为记忆",函数的名称为记忆".

MATLAB now ships with a function just for this purpose. The technique used is called "memoization" and the function's name is "memoize".

签出: https://www.mathworks.com/help/matlab /ref/memoize.html

这篇关于在MATLAB中缓存函数结果的最简洁方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆