help-octave
[Top][All Lists]
Advanced

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

Problem with mexPutVariable


From: DONATI, KORY D CTR USAF AFSPC WROCI/InDyne
Subject: Problem with mexPutVariable
Date: Wed, 22 May 2013 16:18:02 +0000

Hello all,
I asked a similar question previously that went unanswered. I have dug into my 
problem more and have found what I think to be the root cause: mexPutVariable. 
I am still new to using mex files and their language, so I might not have my 
code correct.

I am trying to put an mxarray into the caller workspace for use within an 
octave function. However, it appears that when the option for "caller" is 
selected in mexPutVariable, the array is passed to "base". Here is a simple mex 
source file I made to illustrate my problem. This file compiles and works as 
expected in matlab ver 7.0.6.0. Also included is the .m file I used to test to 
make sure if the caller option in mexPutVariable was working.


/* start: simple_array.c*/
#include"mex.h"
/* Include matrix.h if using matlab.*/
/* #include"matrix.h"*/
void
mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{

/* Create an array of double and an mxarray and a pointer*/
double arr1[5];
mxArray  *array_ptr = NULL;
/* Set up array Elements*/
arr1[0] = 2;
arr1[1] = 4;
arr1[2] = 6;
arr1[3] = 8;
arr1[4] = 10;


/* Create an mxArray. */
   array_ptr = mxCreateDoubleMatrix(1, 5, mxREAL);
   
   /*Set array to the mxarray*/
   mxSetPr(array_ptr, arr1);
   
   /*Pass mxarray to caller workspace... NOT WORKING */
   mexPutVariable ("caller","out_caller",array_ptr);
        
   /*Pass mxarray to base workspace*/
   mexPutVariable ("base","out_base",array_ptr);

   /*Pass mxarray to global workspace*/
   mexPutVariable ("global","out_global",array_ptr);
   
   }

/* end: simple_array.c*/

********************************

% START:run_me.m
function run_me()

simple_array()
whos

% This line returns an error in octave, but not matlab.
display(out_caller)

end
% END: run_me.m



reply via email to

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