-1

how a built-in matlab/octave function can be called from a GTK+2 C code. i know how to call octave functions from C code by Mex files, but i don't know how i can call matlab/octave function from GTK+2 C code. is it possible to use Mex files to call matlab/octave function from a GTK+2 C code. suppose i want to make GUI using GTK+2 C code to display result of addition of two numbers using a matlab/octave function. i have searched on Internet but was not to find what i am looking for. i am not sure if i try to compile it from the matlab/octave how the flags required for GTK+2 will be added

i am posting this code can you please tell me how to compile it without error

when i try to compile it using mkoctfile --mex addition_GUI.c error occurs addition_GUI.c:1:20: fatal error: gtk/gtk.h: No such file or directory compilation terminated.

here is the code

#include<gtk/gtk.h>
#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *in[2], *out[1];

in[0] = mxCreateDoubleScalar(1);
in[1] = mxCreateDoubleScalar(2);

mexCallMATLAB(1, out, 2, in, "addition");
mexCallMATLAB(0, NULL, 1, out, "disp");

mxDestroyArray(in[0]);
mxDestroyArray(in[1]);
mxDestroyArray(out[0]);
}
    void static call(GtkWidget *widget,gpointer data)
{
g_print("\n%s\n",gtk_entry_get_text(GTK_ENTRY(data)));
gint a=3;
gint b=2;
gint x;
x=a+b;
char y[4]; 
    sprintf(y, "%d", x);
    gtk_entry_set_text(GTK_ENTRY(data),y); 
}

    int main(int agrc, char *agrv[])

{
gtk_init(&agrc,&agrv);
GtkWidget *entry,*window,*button,*hbox;

window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window,"delete-event",G_CALLBACK(gtk_main_quit),NULL);

hbox=gtk_hbox_new(0,0);
gtk_container_add(GTK_CONTAINER(window),hbox);
button=gtk_button_new_with_mnemonic("ADD");
entry=gtk_entry_new();
const char* sum="3+2";
gtk_entry_set_text(GTK_ENTRY(entry),sum); 
g_signal_connect(button,"clicked",G_CALLBACK(call),entry);
g_signal_connect(entry,"activate",G_CALLBACK(call),entry);



gtk_box_pack_start(GTK_BOX(hbox),button,0,0,0);

gtk_box_pack_start(GTK_BOX(hbox),entry,0,0,0);

gtk_widget_show_all(window);
gtk_main();
return 0;

}
user3132152
  • 103
  • 4
  • 1
    Have you even tried anything? or are you just hoping for someone here to do the work for you? – Elias Van Ootegem Jan 15 '14 at 19:35
  • @EliasVanOotegem i have tried calling octave function from C code mex files and i was successfull , but i dont know how to compile it for GTK+2 code – user3132152 Jan 15 '14 at 19:40
  • @user3132152: I think you are confusing things here; MEX/OCT-files (written in C/C++) are only callable by MATLAB/Octave. From what I understand you are looking to do the opposite of calling MATLAB/Octave from a standalone C/C++ program, which I have shown in answer below... – Amro Jan 17 '14 at 19:46

1 Answers1

0

Octave can be embedded inside standalone C++ program. See here for an example.

MATLAB can also be used from your applications using the MATLAB Engine API.

Community
  • 1
  • 1
Amro
  • 123,847
  • 25
  • 243
  • 454