help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error about mkoctfile and Octave update..Thank you!


From: Søren Hauberg
Subject: Re: Error about mkoctfile and Octave update..Thank you!
Date: Tue, 07 Nov 2006 19:47:03 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060918)

Hi,
  First of all I wouldn't use pointers if I were you. You didn't
say what you're problem was so I'm guessing a bit. Your program
has a few bugs:
1) resAddm is const yet you try to alter it's values.
2) in C++ matrices use zero based indexing -- you use 1 based indexing.
Other then that you program should work. Here is a fixed version:

#include <octave/oct.h>
DEFUN_DLD (addoctmatr, args, ,
 "The addition of two spreaded matrices.")
{
    octave_value_list retval;

    const Matrix Am = args(0).matrix_value();
    int mrows = Am.rows();
    int ncols = Am.cols();
    const Matrix Bm = args(1).matrix_value();
    Matrix resAddm (mrows, ncols);
    for(int i = 0; i < mrows; i++)
    {
        for(int j = 0; j < ncols; j++)
        {
            resAddm(i,j) = Am(i,j) + Bm(i,j);
        }
    }
    retval.append(resAddm);
    return retval;
}


Hope that helps,
Søren


钟 伟生 skrev:
Dear All,

I am a new comer to the octave andI tried to write an .cc file about the addition of two integral matrices. But there are still too many warning when i mkoctfile it... I would be so grateful for any help. Another, my octave release is 2.1.73 under cygwin, is anyone know how to update to 2.9.8...I download the 2.9.8 file, but how to install?

Thank you very much!

Best Regards,
Weisheng

#include <octave/oct.h>
DEFUN_DLD (addoctmat, args, ,
 "The addition of two spreaded matrices.")
{
    octave_value retval;
    const Matrix Am = args(0).matrix_value();
    double *A = Am.fortran_vec();
    int mrows = Am.rows();
    int ncols = Am.cols();
    const Matrix Bm = args(1).matrix_value();
    double *B = Bm.fortran_vec();
    const Matrix resAddm (mrows, ncols);
    double *resAdd = resAddm.fortran_vec();
resAdd[0] = 0.0;
    for (int i = 0; i < mrows; i++)
    {
        for (int j = 0; j < ncols; j++)
        {
            *(resAdd+j*mrows+i) = *(Am+j*mrows+i) + *(Bm+j*mrows+i);
        }
    }
    retval = resAddm;
    return retval;
}

And, if I donot use the pointer, is seems better...but still donot work.....

#include <octave/oct.h>
DEFUN_DLD (addoctmatr, args, ,
 "The addition of two spreaded matrices.")
{
    octave_value retval;

const Matrix Am = args(0).matrix_value(); int mrows = Am.rows(); int ncols = Am.cols(); const Matrix Bm = args(1).matrix_value();
    const Matrix resAddm (mrows, ncols);
    for(int i = 1; i <= mrows; i++)
    {
        for(int j = 1; j <= ncols; j++)
        {
            resAddm(i,j) = Am(i,j) + Bm(i,j);
        }
    }
    retval = resAddm;
    return retval;
}

_________________________________________________________________
与联机的朋友进行交流,请使用 Live Messenger; http://get.live.com/messenger/overview


------------------------------------------------------------------------

_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

[Prev in Thread] Current Thread [Next in Thread]