Octave c++ and VS2010

后端 未结 2 750
醉梦人生
醉梦人生 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 <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;
    }
    

    with an output:

    x =
     0.165897
     0.0239711
     0.957456
     0.830028
     0.859441
     0.513797
     0.870601
     0.0643697
     0.0605021
     0.153486
    
    0 讨论(0)
  • 2021-01-02 09:23

    I'd guess that its actually stopped pointing at the next line and the error actually lies at this line:

    f_arg(0) = octave_value(NumRands);
    

    You seem to be attempting to get a value (which value?) from a vector and then assigning it to element 0 of a vector that has not been defined as a vector.

    I don't really know though ... I've never tried writing octave code like that. I'm just trying to work it out by translating the code to standard matlab/octave code and that line seems really odd to me ...

    0 讨论(0)
提交回复
热议问题