Octave c++ and VS2010

后端 未结 2 763
醉梦人生
醉梦人生 2021-01-02 09:05

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

I have downloaded octave-3.6.1-vs2010-setup-1.exe. Created a new project, added octave include folder to incl

2条回答
  •  时光取名叫无心
    2021-01-02 09:18

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

    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.

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

    Here is the code I tested:

    #include 
    #include 
    #include 
    #include 
    
    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;
    }
    

    with an output:

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

提交回复
热议问题