(no subject)

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

(no subject)

I need to use the following method to work with the library libSVM: Qt+Octave+libSVM+(Linux/Mac). LibSVM works with Octave without Qt, but I need to use Qt to run built-in and external functions Octave. SVMTrain is a mex-function and when calling it occurs segmentation fault 11. I don't know how to solve this problem, please help to resolve this.

#include <QCoreApplication>
#include <iostream>
#include <string>
#include <oct.h>
#include <octave.h>
#include <parse.h>
#include <toplev.h>
#include <interpreter.h>
#include <builtin-defun-decls.h>
#include <Cell.h>
#include <Matrix.h>
#include <cmd-edit.h>
#include <cmd-hist.h>
#include <file-ops.h>
#include <file-stat.h>
#include <oct-env.h>
#include <oct-time.h>
#include <quit.h>
#include <comment-list.h>
#include <defaults.h>
#include <dirfns.h>
#include <dynamic-ld.h>
#include <error.h>
#include <input.h>
#include <lex.h>
#include <load-path.h>
#include <oct-hist.h>
#include <oct-map.h>
#include <ov-fcn-handle.h>
#include <ov-usr-fcn.h>
#include <ov-null-mat.h>
#include <toplev.h>
#include <pager.h>
#include <parse.h>
#include <pt-all.h>
#include <pt-eval.h>
#include <symtab.h>
#include <token.h>
#include <unwind-prot.h>
#include <utils.h>
#include <variables.h>

void runscript(const std::string &file)
    int parse_status = 0;
    // с выводом результата загрузки workspace
    //eval_string(file, false, parse_status);
    // без вывода результата загрузки workspace
    eval_string(file, false, parse_status, 0);

int main(int argc, char *argv[])
    // create qt app
    QCoreApplication app(argc, argv);
    // create octave app
    string_vector octave_argv (2);
    octave_argv(0) = "embedded";
    octave_argv(1) = "-q";
    octave::embedded_application app_oct(2, octave_argv.c_str_vec());
    //octave_main(2, octave_argv.c_str_vec (), true);
    // verified code for show workable octave
    octave_value_list abs_in;
    // complex variable
    abs_in(0) = Complex(3, 4); // result = 5
    // run built-in function 'abs'
    octave_value_list abs_ret = feval("abs", abs_in);
    // to terminal
    std::cout << "Abs result = " << abs_ret(0).double_value() << std::endl;
    // load my function
    load_fcn_from_file("Emulate.m", "", "", "", "Emulate", true);
    // load_1 octave workspace ( work )) )
    runscript("load EmulateData.mat;");
    // load_2 octave workspace ( not work (( )
    /*octave_value_list args;
    // MATLAB 6 (save -6 EmulateData.mat)
    args(0) = "EmulateData.mat";
    args(1) = "a";
    feval("load", args, 0);*/
    // get variable from workspace
    SparseMatrix trainData = get_top_level_value("trainData", false).sparse_matrix_value();
    Matrix trainLabel = get_top_level_value("trainLabel", false).matrix_value();
    SparseMatrix testData = get_top_level_value("testData", false).sparse_matrix_value();
    Matrix testLabel = get_top_level_value("testLabel", false).matrix_value();
    // create list with created variables for svmtrain-function
    octave_value_list in;
    in(0) = trainLabel;
    in(1) = trainData;
    in(2) = testLabel;
    in(3) = testData;
    // run external function with svmtrain-function
    octave_value_list result = feval("Emulate", in, 1);
    std::cout << "<= EXIT" << std::endl;
    return 0;


QT += widgets gui


LIBS += -L /usr/local/Cellar/octave/4.2.1_6/lib/octave/4.2.1 -loctave -loctinterp

INCLUDEPATH += /usr/local/Cellar/octave/4.2.1_6/include/octave-4.2.1/octave

CONFIG += c++11 console
CONFIG -= app_bundle

Help-octave mailing list
[hidden email]