Dear helpers,
It is my very first day with Octave so excuse for dummy question !!
I developped a C++ application for my all day work.
I would like to add scripting possibility to my application that's why I am now evaluating Octave.
I use :
- windows Xp 32 bit
- octave 3.2.4 installed witht the windows installer
- Octave into my C++ application (compiled with Qt and mingw)
My problem : when I launch a script containing a "plot" function call from my C application, nothing happens !!
I imagine it is a problem from gnuplot configuration. (I precise gnuplot.exe is in the path)
Help would be very appreciated ;-))
Thanks,
Christophe
########### script.m ###################
function [A, B, C] = exampleOctaveFunction (inScalar, inString, inMatrix)
# modify in parameters to see how Octave works
result.a = (inScalar * pi);
result.b = "toto";
inMatrix(1,1) = 99;
result.c = (inMatrix + 10);
A = result.a;
B = result.b;
C = result.c;
# add files to plot
addpath("C:\\Octave\\3.2.4_gcc-4.4.0\\share\\octave\\3.2.4\\m\\plot");
addpath("C:\\Octave\\3.2.4_gcc-4.4.0\\share\\octave\\3.2.4\\m\\general");
addpath("C:\\Octave\\3.2.4_gcc-4.4.0\\share\\octave\\3.2.4\\m\\strings");
autoload ("find", "C:\\Octave\\3.2.4_gcc-4.4.0\\libexec\\octave\\3.2.4\\oct\\i686-pc-mingw32\\find.oct");
# test plot
x = -10:0.1:10;
disp("init plot");
plot(x,sin(x));
disp("plot finished");
endfunction
############ C program ################
#include <QtCore/QCoreApplication>
#include <iostream>
#include <oct.h>
#include <octave.h>
#include <parse.h>
#include <toplev.h> /* do_octave_atexit */
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// create an Octave Matrix
Matrix inMatrix(2, 3);
inMatrix(0, 0) = 10;
inMatrix(0, 1) = 9;
inMatrix(0, 2) = 8;
inMatrix(1, 0) = 7;
inMatrix(1, 1) = 6;
// create an argument list for the octave function
octave_value_list functionArguments;
functionArguments(0) = 2;
functionArguments(1) = "D. Humble";
functionArguments(2) = inMatrix;
// execute Octave script
const char * argvv [] = {"" /* name of program, not relevant */, "--silent"};
octave_main(2, (char **) argvv, 1);
const octave_value_list result = feval("exampleOctaveFunction", functionArguments, 1);
// get and display resluts from Octave script
if (!error_state && result.length () > 0)
{
std::cout << "resultScalar is " << result(0).scalar_value () << std::endl;
std::cout << "resultString is " << result(1).string_value () << std::endl;
std::cout << "resultMatrix is\n" << result(2).matrix_value ();
}
else
{
std::cout << "invalid\n";
}
do_octave_atexit ();
return a.exec();
}