在 C 中使用 octave 内置函数

Using octave built-in function in C

我被告知要在 Octave 中使用 C 编译这个程序。在使用 Octave 之前,我已经成功地编译了一个简单的 C 程序,但是对于这个,我已经尝试过,但我不知道如何用 C 编译它,尽管我已经尝试将一些 C++ 语言更改为 C 语言。

 #include <iostream>

 #include <octave/oct.h>

 int main (void)

 {
 std::cout << "Hello Octave world!\n";

 int n = 2;

 Matrix a_matrix = Matrix (n, n);

 for (octave_idx_type i = 0; i < n; i++)

 for (octave_idx_type j = 0; j < n; j++)

 a_matrix(i,j) = (i + 1) * 10 + (j + 1);

 std::cout << a_matrix;

 return 0;
 }

那么这个问题有什么解决办法吗? 非常感谢您,对于我在 post 中所犯的任何错误,我深表歉意,因为我在使用 Octave 和在本论坛中还是个新手。

编辑(在 Alter Mann 的回答之后):

所以这是我的 C 程序代码

#include <stdio.h>

int main(void)
{
        printf("Hello Octave World!");

    int n=2;
    Matrix a_matrix = Matrix (n, n);

    for (octave_idx_type i=0; i<n; i++)
    {
            for (octave_idx_type j=0; j<n; j++)
            {
                    a_matrix(i,j) = (i+1) * 10 + (j+1);
            }

            printf ("%d", &a_matrix);
    }
    return 0;
}

但是我遇到了这个错误

standalone.c: In function ‘main’:
standalone.c:8: error: ‘Matrix’ undeclared (first use in this function)
standalone.c:8: error: (Each undeclared identifier is reported only once
standalone.c:8: error: for each function it appears in.)
standalone.c:8: error: expected ‘;’ before ‘a_matrix’
standalone.c:10: error: ‘octave_idx_type’ undeclared (first use in this function)
standalone.c:10: error: expected ‘;’ before ‘i’
standalone.c:10: error: ‘i’ undeclared (first use in this function)
standalone.c:12: error: expected ‘;’ before ‘j’
standalone.c:12: error: ‘j’ undeclared (first use in this function)
standalone.c:14: warning: implicit declaration of function ‘a_matrix’
standalone.c:17: error: ‘a_matrix’ undeclared (first use in this function)

#include <iostream>

应该是

#include <stdio.h>

std::cout << a_matrix;

应该是

printf("%d", a_matrix);

但是<octave/oct.h>不能用在C:

A.1.1 Getting Started with Oct-Files

The first critical line is #include which makes available most of the definitions necessary for a C++ oct-file. Note that octave/oct.h is a C++ header and cannot be directly #include’ed in a C source file, nor any other language.

Alternative:

The interface is centered around supporting the languages C++, C, and Fortran. Octave itself is written in C++ and can call external C++/C code through its native oct-file interface. The C language is also supported through the mex-file interface for compatibility with MATLAB. Fortran code is easiest to reach through the oct-file interface.