八度C ++和VS2010 [英] Octave c++ and VS2010

查看:145
本文介绍了八度C ++和VS2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual C ++中使用Octave.

I'm trying to Use Octave with Visual C++.

我已经下载了 octave-3.6.1-vs2010-setup-1.exe .创建一个新项目,将octave include文件夹添加到路径,将octinterp.liboctave.lib包含到lib路径,然后将Octave bin文件夹添加为运行目录.

I have downloaded octave-3.6.1-vs2010-setup-1.exe. Created a new project, added octave include folder to include path, octinterp.lib and octave.lib to lib path, and I added Octave bin folder as running directory.

程序会编译并运行正常,但会导致异常的feval函数除外.

The program compiles and runs fine except feval function that causes the exception:

Microsoft C ++异常:内存位置0x0012faef处的octave_execution_exception

Microsoft C++ exception: octave_execution_exception at memory location 0x0012faef

在八度音阶方面:

无效的大小调整操作或对边界数组元素的分配不明确.

Invalid resizing operation or ambiguous assignment to an out-of-bounds array element.

我在做什么错了?

独立程序的代码:

#include <octave/octave.h>
#include <octave/oct.h>
#include <octave/parse.h>

int main(int argc, char **argv)
{
    if (octave_main (argc, argv, true))
    {
        ColumnVector NumRands(2);
        NumRands(0) = 10;
        NumRands(1) = 1;
        octave_value_list f_arg, f_ret;
        f_arg(0) = octave_value(NumRands);
        f_ret = feval("rand",f_arg,1);
        Matrix unis(f_ret(0).matrix_value());
    }
    else
    {
        error ("Octave interpreter initialization failed");
    }
    return 0;
}

谢谢.

推荐答案

我自己尝试过,问题似乎出在feval行.

I tried it myself, and the problem seems to originate from the feval line.

现在我没有关于为什么的解释,但是通过简单地切换到"Release"配置而不是"Debug"配置解决了该问题.

Now I don't have an explanation as to why, but the problem was solved by simply switching to the "Release" configuration instead of the "Debug" configuration.

我在WinXP上使用Octave3.6.1_vs2010构建和VS2010.

I am using the Octave3.6.1_vs2010 build, with VS2010 on WinXP.

这是我测试过的代码:

#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>

int main(int argc, char **argv)
{
    // Init Octave interpreter
    if (!octave_main(argc, argv, true)) {
        error("Octave interpreter initialization failed");
    }

    // x = rand(10,1)
    ColumnVector sz(2);
    sz(0) = 10; sz(1) = 1;
    octave_value_list in = octave_value(sz);
    octave_value_list out = feval("rand", in, 1);

    // print random numbers
    if (!error_state && out.length () > 0) {
        Matrix x( out(0).matrix_value() );
        std::cout << "x = \n" << x << std::endl;
    }

    return 0;
}

具有输出:

x =
 0.165897
 0.0239711
 0.957456
 0.830028
 0.859441
 0.513797
 0.870601
 0.0643697
 0.0605021
 0.153486

这篇关于八度C ++和VS2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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