主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

matlab::cpplib::MATLABLibrary::fevalAsync

从可部署存档异步执行 MATLAB 函数

描述

执行具有 1 个输出 MATLAB® 数据数组参量和 1 个输入 MATLAB 数据数组参量的函数

函数名称为 u16string

FutureResult<matlab::data::Array> fevalAsync(const std::u16string &function, const matlab::data::Array &arg, const std::shared_ptr<StreamBuffer> &output = std::shared_ptr<StreamBuffer>(), const std::shared_ptr<StreamBuffer> &error = std::shared_ptr<StreamBuffer>())

函数名称作为字符串

FutureResult<matlab::data::Array> fevalAsync(const std::string &function, const matlab::data::Array &arg, const std::shared_ptr<StreamBuffer> &output = std::shared_ptr<StreamBuffer>(), const std::shared_ptr<StreamBuffer> &error = std::shared_ptr<StreamBuffer>())

执行具有 1 个输出 MATLAB 数据数组参量和任意数量的输入 MATLAB 数据数组参量的函数

函数名称为 u16string

FutureResult<matlab::data::Array> fevalAsync(const std::u16string &function, const std::vector<matlab::data::Array> &args, const std::shared_ptr<StreamBuffer> &output = std::shared_ptr<StreamBuffer>(), const std::shared_ptr<StreamBuffer> &error = std::shared_ptr<StreamBuffer>())

函数名称作为字符串

FutureResult<matlab::data::Array> fevalAsync(const std::string &function, const std::vector<matlab::data::Array> &args, const std::shared_ptr<StreamBuffer> &output = std::shared_ptr<StreamBuffer>(), const std::shared_ptr<StreamBuffer> &error = std::shared_ptr<StreamBuffer>())

执行具有任意数量的输出 MATLAB 数据数组参量和任意数量的输入 MATLAB 数据数组参量的函数

函数名称为 u16string

FutureResult<std::vector<matlab::data::Array>> fevalAsync(const std::u16string &function, const size_t nlhs, const std::vector<matlab::data::Array> &args, const std::shared_ptr<StreamBuffer> &output = std::shared_ptr<StreamBuffer>(), const std::shared_ptr<StreamBuffer> &error = std::shared_ptr<StreamBuffer>())

函数名称作为字符串

FutureResult<std::vector<matlab::data::Array>> fevalAsync(const std::string &function, const size_t nlhs, const std::vector<matlab::data::Array> &args, const std::shared_ptr<StreamBuffer> &output = std::shared_ptr<StreamBuffer>(), const std::shared_ptr<StreamBuffer> &error = std::shared_ptr<StreamBuffer>())

使用本机标量输入和输出参量执行函数

函数名称为 u16string

template<class ReturnType, typename...RhsArgs>

FutureResult<ReturnType> fevalAsync(const std::u16string &function, RhsArgs&&... rhsArgs)

函数名称作为字符串

template<class ReturnType, typename...RhsArgs>

FutureResult<ReturnType> fevalAsync(const std::string &function, RhsArgs&&... rhsArgs)

使用本机标量输入和输出参量执行函数,并进行输出重定向

函数名称为 u16string

template<class ReturnType, typename...RhsArgs>

FutureResult<ReturnType> fevalAsync(const std::u16string &function, const std::shared_ptr<StreamBuffer> &output, const std::shared_ptr<StreamBuffer> &error, RhsArgs&&... rhsArgs)

函数名称作为字符串

template<class ReturnType, typename...RhsArgs>

FutureResult<ReturnType> fevalAsync(const std::string &function, const std::shared_ptr<StreamBuffer> &output, const std::shared_ptr<StreamBuffer> &error, RhsArgs&&... rhsArgs)

异步调用 C++ 共享库中的打包 MATLAB 函数:

  • 不重定向标准输出或标准错误:

  • 使用标准输出重定向:

  • 通过重定向标准输出和标准错误:

其中,

LhsItem原生标量
RhsArgs

一个或多个本机标量的序列。

StreamBuffer

std::basic_streambuf<char16_t>

它传递函数的名称,后跟参量。如果在库中找不到指定的函数,则会引发异常。

支持的本机类型:

  • bool

  • int8_t

  • int16_t

  • int32_t

  • int64_t

  • uint8_t

  • uint16_t

  • uint32_t

  • uint64_t

  • float

  • double

  • std:string

  • std::u16string

  • std::complex<T> 其中 T 是数值类型之一。

参数

const std::u16string &function

const std::string &function

要评估的已编译 MATLAB 函数的名称,指定为 u16stringstring
const size_t nlhs返回值的数量。
const std::vector<matlab::data::Array> argsMATLAB 函数使用的参量。
const matlab::data::Array arg具有单一输入的 MATLAB 函数使用的参量。
const RhsArgs& rhsArgs

模板参数包由一个或多个参量的序列组成,每个参数都是本机标量。

const std::shared_ptr<StreamBuffer>& output用于存储 MATLAB 函数标准输出的字符串缓冲区。
const std::shared_ptr<StreamBuffer>& error用于存储 MATLAB 函数的错误输出的字符串缓冲区。

返回值

FutureResult

采用 LhsItem 的任何允许类型。

异常

matlab::cpplib::CanceledException

MATLAB 函数被取消。

matlab::cpplib::InterruptedException

MATLAB 函数被中断。

matlab::cpplib::MATLABNotAvailableError

MATLAB 会话不可用。

matlab::cpplib::MATLABSyntaxError

MATLAB 函数返回了语法错误。

matlab::cpplib::MATLABExecutionError

该函数返回 MATLAB 错误。

matlab::cpplib::TypeConversionError

MATLAB 函数的结果不能转换为用户特定的类型。

示例

在 C++ 共享库中异步执行用户编写的 MATLAB 函数 repeatdouble

 / Call the function repeatdouble, which iteratively continues to
        // double a number, printing out results along the way.  The 
        // (optional) second and third parameters determine, respectively, how 
        // many iterations should be performed and how many seconds should 
        // elapse between operations. We call the function asynchronously, 
        // then call it again (also asynchronously) with a different base 
        // number before all the iterations from the first call have completed.

        // We pass the arguments to the function as C++ native types (namely 
        // doubles) rather than a md::Array. The return type is also a native 
        // type (a double), so fevalAsync and the FutureResult need to take 
        // "double" as a template parameter.
        mc::FutureResult<double> futureA = lib->fevalAsync<double>(
            mc::convertUTF8StringToUTF16String("repeatdouble"), 10.0, 3.0, 0.5);
        mc::FutureResult<double> futureB = lib->fevalAsync<double>(
            mc::convertUTF8StringToUTF16String("repeatdouble"), 11.0, 3.0, 0.5);
            
        // Get the result once it's ready.
        double resultA = futureA.get();
        double resultB = futureB.get();

版本历史记录

在 R2018a 中推出