help-octave
[Top][All Lists]
Advanced

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

Re: Assigning values to Octave matrix in C++ code


From: Shamika Mohanan
Subject: Re: Assigning values to Octave matrix in C++ code
Date: Sat, 8 Oct 2016 12:44:39 +0530

Copying is fine. Can you show how to do it in a single operation using a constructor?

Shamika

On Fri, Oct 7, 2016 at 9:46 PM, Mike Miller <address@hidden> wrote:
On Fri, Oct 07, 2016 at 11:05:00 +0530, Shamika Mohanan wrote:
> Hello,
>
> I'm using Octave API in c++ code. I'm creating a double matrix and
> assigning values from a pointer to the matrix using for loops.
>
> Matrix matrix_double = Matrix (iRows,iCols);for (r=0;r<iRows;r++)
>                 {
>                     for(c=0;c<iCols;c++)
>                     {
>                         matrix_double(r,c)=(pdblReal[r+iRows*c]);
>
>                     }
>                 }
>
> I want to avoid using for loops as much as possible. I tried this-
>
> matrix_double(*pdblReal,iRows,iCols);
>
> where pdblReal points to the matrix values. This didn't raise any errors
> while compiling, the values were not assigned to matrix_double matrix
> during execution.
>
> Is it possible to assign values to a double (and other data type) matrix
> using pointers? If yes, what did I do wrong?

Can you clarify, do you want to create a Matrix to wrap your existing
buffer, such that no data is copied? Or do you want a constructor that
copies the entire array from your buffer into the new Matrix in a single
operation?

The former is not possible, Octave's array classes own their memory
representation and do not offer a way to wrap an Octave array around an
existing C++ array.

The latter is possible if you have an STL container like a std::array or
a std::vector.

Do you have your code hosted somewhere publically so we can help you
with more direct references?

--
mike


reply via email to

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