Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
changing input array within mex function

Subject: changing input array within mex function

From: Amit

Date: 9 Jul, 2011 15:56:10

Message: 1 of 3

Hi,

I want to change the one input vector in mex file based on the other input variables. I don't want to copy that array and send back the modified array back because it is of very large size. It is explained below-

I have three vectors

A=[10 20 30... 60...90...120... 1000]
B=[3 6 9 12]
C=[35 65 95 125]

I want to write a mex function that modifies the vector A by using vectors B and C. This mex file should substitute for the following MATLAB work

A(B)=C

and results should be
A=[10 20 35... 65...95...125... 1000]

Because this happens multiple times I need to do this using for loop. In each loop the B and C changes. hence I want to use mex file. But I don't want to copy the vector A in mex file because it is of large size.
Please help me to solve this problem.

Thanks n advance,
Amit

Subject: changing input array within mex function

From: Amit

Date: 9 Jul, 2011 18:26:10

Message: 2 of 3

To make it more clear
I just wanted to know how to modify the input variable A mentioned above using B and C using pointer to A within the mex file and not by modifying it after obtaining a copy of A.


Thanks,
Amit

Subject: changing input array within mex function

From: James Tursa

Date: 9 Jul, 2011 21:31:09

Message: 3 of 3

"Amit " <amitsingh.singh@gmail.com> wrote in message <iv9tmq$p3l$1@newscl01ah.mathworks.com>...
> Hi,
>
> I want to change the one input vector in mex file based on the other input variables. I don't want to copy that array and send back the modified array back because it is of very large size. It is explained below-
>
> I have three vectors
>
> A=[10 20 30... 60...90...120... 1000]
> B=[3 6 9 12]
> C=[35 65 95 125]
>
> I want to write a mex function that modifies the vector A by using vectors B and C. This mex file should substitute for the following MATLAB work
>
> A(B)=C
>
> and results should be
> A=[10 20 35... 65...95...125... 1000]
>
> Because this happens multiple times I need to do this using for loop. In each loop the B and C changes. hence I want to use mex file. But I don't want to copy the vector A in mex file because it is of large size.
> Please help me to solve this problem.
>
> Thanks n advance,
> Amit

But in your above example the expression A(B) = C does in fact modify A in-place at the MATLAB level. No copy of A is made. You don't need a mex for this. Are you saying that the above expression is running out of memory?

James Tursa

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us