Thread Subject: C to Matlab conversion

Subject: C to Matlab conversion

From: Julia Woody

Date: 22 Jul, 2009 18:45:02

Message: 1 of 12

I want to convert a few C files to matlab, when I try to use mex function I am getting error :( So, I wil try to convert it page by page. One of those page is the following, can you help me by sending the matlab codes of the following codes:

#include <stdlib.h>
#include "idvol.h"
#include "idprint.h"


#define DEBUG 0
 
PPPVOLUME
IdVolAlloc(int sx, int sy, int sz, int ty)
{
PRIVATE_VOLUME *pvol;
PPPVOLUME pv = NULL;
int plan, ligne;

if (!(ty & IDO_TYPE) == VOL) {
printf
("Allocation impossible. Objet de type incompatible.");
return (PPPVOLUME) NULL;
}

pvol = (PRIVATE_VOLUME *)
calloc(1, sizeof(PRIVATE_VOLUME) + sz * sizeof(char **));

if (pvol == NULL) {
printf("Echec Alloc Volume (partie privee)\n");
free(pvol);
return (PPPVOLUME) NULL;
}
if (DEBUG) printf("pvol %p\n",pvol);

pvol->_fichier = 0;
pvol->_message = 0;
pv = (PPPVOLUME) & pvol[1];
IdVolDimX(pv) = sx;
IdVolDimY(pv) = sy;
IdVolDimZ(pv) = sz;
IdVolUsedNbX(pv) = 0;
IdVolUsedNbY(pv) = 0;
IdVolUsedNbZ(pv) = 0;
IdVolType(pv) = ty;
pvol->subObject = 0;


sx = ((ty & TY_SIZE) == TY_BIT) ? ((sx + 7) >> 3) : sx;

pv[0] = (void **) malloc( sz * sy * sizeof(void *));

if (pv[0] == NULL) {
printf("Echec Alloc Volume (pointeurs sur Lignes)\n");
free(pvol);
return (PPPVOLUME) NULL;
}

if (DEBUG) printf("pv[0] %p\n",pv[0]);

pv[0][0] = (void *) malloc( sz * sy * sx * IdSizeOfType(pv));

if (pv[0][0] == NULL) {
printf("Echec Alloc Volume (voxels)\n");
free(pvol);
return (PPPVOLUME) NULL;
}

for (plan = 0; plan < sz; plan++) {
pv[plan]= pv[0] + plan * sy;
if (DEBUG) printf("\tpv[%d] %p\n",plan, pv[plan]);
for (ligne=0; ligne<sy; ligne++) {
pv[plan][ligne] = (((char *)pv[0][0]) + (plan*sy + ligne )*sx*IdSizeOfType(pv) );
if (DEBUG) printf("\t pv[%d][%d] %p\n",plan, ligne, pv[plan][ligne]);
}
}
return (pv);
}


void
_IdVolFree(PPPVOLUME * pv)
{
if (*pv) {
if (_IdVolPrivate(*pv)->subObject == 0) {
/*
*Liberation des voxels si PAS un ss-objet
*/
free((*pv)[0][0]);
}
free((*pv)[0]);

if (_IdVolPrivate(*pv)->_message)
free((_IdVolPrivate(*pv)->_message));
//_IdVolPrivate(*pv)->_message = 0; // inutile
if (_IdVolPrivate(*pv)->_fichier)
free((_IdVolPrivate(*pv)->_fichier));
//_IdVolPrivate(*pv)->_fichier = 0; // inutile

free(_IdVolPrivate(*pv));
*pv = 0;
}
}

Subject: C to Matlab conversion

From: us

Date: 22 Jul, 2009 19:25:02

Message: 2 of 12

"Julia Woody" <jwwoody0@gmail.com> wrote in message <h47mne$ot4$1@fred.mathworks.com>...
> I want to convert a few C files to matlab, when I try to use mex function I am getting error :( So, I wil try to convert it page by page. One of those page is the following, can you help me by sending the matlab codes of the following codes:
>
> #include <stdlib.h>
> ...

i'll get to it right away; just give me a minute...

us

Subject: C to Matlab conversion

From: James Tursa

Date: 22 Jul, 2009 22:54:02

Message: 3 of 12

"Julia Woody" <jwwoody0@gmail.com> wrote in message <h47mne$ot4$1@fred.mathworks.com>...
> I want to convert a few C files to matlab, when I try to use mex function I am getting error :( So, I wil try to convert it page by page. One of those page is the following, can you help me by sending the matlab codes of the following codes:
>
> #include <stdlib.h>

No one is going to do this for you. Maybe you could show the code for your mex function instead and we could help you set it up properly.

James Tursa

Subject: C to Matlab conversion

From: Rose Watchy

Date: 23 Jul, 2009 05:34:02

Message: 4 of 12

"us " <us@neurol.unizh.ch> wrote in message <h47p2e$m6d$1@fred.mathworks.com>...
> "Julia Woody" <jwwoody0@gmail.com> wrote in message <h47mne$ot4$1@fred.mathworks.com>...
> > I want to convert a few C files to matlab, when I try to use mex function I am getting error :( So, I wil try to convert it page by page. One of those page is the following, can you help me by sending the matlab codes of the following codes:
> >
> > #include <stdlib.h>
> > ...
>
> i'll get to it right away; just give me a minute...
>
> us

Dear

I have send an email to you about the C files and waiting for your answer, I am really thankful to you

Subject: C to Matlab conversion

From: Rose Watchy

Date: 23 Jul, 2009 05:41:01

Message: 5 of 12

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <h485aa$dod$1@fred.mathworks.com>...
> "Julia Woody" <jwwoody0@gmail.com> wrote in message <h47mne$ot4$1@fred.mathworks.com>...
> > I want to convert a few C files to matlab, when I try to use mex function I am getting error :( So, I wil try to convert it page by page. One of those page is the following, can you help me by sending the matlab codes of the following codes:
> >
> > #include <stdlib.h>
>
> No one is going to do this for you. Maybe you could show the code for your mex function instead and we could help you set it up properly.
>
> James Tursa

Dear James,

I have written the following codes to be able to run the C codes from matlab;
files=dir('*.c');
for i=1:length(files)
    mex(files(i).name,'-v');
end

The error is:
Cannot open include file: 'stdint.h': No such file or directory

I have found the file from internet (http://www.opensource.apple.com/source/gcc/gcc-937.2/stdint.h) and added to the same directory but I am still getting the same error. Therefore, I have to convert each C file to matlab manually by recoding all codes. But, some type definitions are very different and I dont know how to convert to matlab so if someone can help me by converting a few C files then I can try to do similar changings for all C files

thanks..

Subject: C to Matlab conversion

From: dpb

Date: 23 Jul, 2009 05:45:14

Message: 6 of 12

Rose Watchy wrote:
> "us " <us@neurol.unizh.ch> wrote in message
> <h47p2e$m6d$1@fred.mathworks.com>...
>> "Julia Woody" <jwwoody0@gmail.com> wrote in message
>> <h47mne$ot4$1@fred.mathworks.com>...
>>> I want to convert a few C files to matlab, when I try to use mex
>>> function I am getting error :( So, I wil try to convert it page
>>> by page. One of those page is the following, can you help me by
>>> sending the matlab codes of the following codes:
>>>
>>> #include <stdlib.h> ...
>> i'll get to it right away; just give me a minute...
>>
>> us
>
> Dear
>
> I have send an email to you about the C files and waiting for your
> answer, I am really thankful to you

Oh, the irony... :)

--

Subject: C to Matlab conversion

From: Steve Amphlett

Date: 23 Jul, 2009 07:18:01

Message: 7 of 12

dpb <none@non.net> wrote in message <h48tjs$q8h$2@news.eternal-september.org>...
> Rose Watchy wrote:
> > "us " <us@neurol.unizh.ch> wrote in message
> > <h47p2e$m6d$1@fred.mathworks.com>...
> >> "Julia Woody" <jwwoody0@gmail.com> wrote in message
> >> <h47mne$ot4$1@fred.mathworks.com>...
> >>> I want to convert a few C files to matlab, when I try to use mex
> >>> function I am getting error :( So, I wil try to convert it page
> >>> by page. One of those page is the following, can you help me by
> >>> sending the matlab codes of the following codes:
> >>>
> >>> #include <stdlib.h> ...
> >> i'll get to it right away; just give me a minute...
> >>
> >> us
> >
> > Dear
> >
> > I have send an email to you about the C files and waiting for your
> > answer, I am really thankful to you
>
> Oh, the irony... :)

Irony?? This is just a case of someone not recognising a joke/leg-pull.

Subject: C to Matlab conversion

From: Bruno Luong

Date: 23 Jul, 2009 11:20:03

Message: 8 of 12

"Julia Woody" <jwwoody0@gmail.com> wrote in message <h47mne$ot4$1@fred.mathworks.com>...
> I want to convert a few C files to matlab, when I try to use mex function I am getting error :( So, I wil try to convert it page by page. One of those page is the following, can you help me by sending the matlab codes of the following codes:
>

Just a though but
- making the MEX working is certainly easier or at least less tedious than converting C to Matlab.
- I have not seen a single time where this board doing a free work to someone, even for a not-tedious one.

Bruno

Subject: C to Matlab conversion

From: Titus Edelhofer

Date: 23 Jul, 2009 13:54:28

Message: 9 of 12


"Rose Watchy" <Rose.Watchy@gmail.com> schrieb im Newsbeitrag
news:h48t5d$828$1@fred.mathworks.com...
> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message
> <h485aa$dod$1@fred.mathworks.com>...
>> "Julia Woody" <jwwoody0@gmail.com> wrote in message
>> <h47mne$ot4$1@fred.mathworks.com>...
>> > I want to convert a few C files to matlab, when I try to use mex
>> > function I am getting error :( So, I wil try to convert it page by
>> > page. One of those page is the following, can you help me by sending
>> > the matlab codes of the following codes:
>> >
>> > #include <stdlib.h>
>>
>> No one is going to do this for you. Maybe you could show the code for
>> your mex function instead and we could help you set it up properly.
>>
>> James Tursa
>
> Dear James,
>
> I have written the following codes to be able to run the C codes from
> matlab;
> files=dir('*.c');
> for i=1:length(files)
> mex(files(i).name,'-v');
> end
>
> The error is:
> Cannot open include file: 'stdint.h': No such file or directory
>
> I have found the file from internet
> (http://www.opensource.apple.com/source/gcc/gcc-937.2/stdint.h) and added
> to the same directory but I am still getting the same error. Therefore, I
> have to convert each C file to matlab manually by recoding all codes. But,
> some type definitions are very different and I dont know how to convert to
> matlab so if someone can help me by converting a few C files then I can
> try to do similar changings for all C files
>
> thanks..

Hi,
a mex file is not just any C-file that you compile with calling mex instead
of your C-compiler, but it has an interface to be called (void
mexFunction(...)), and you need to pass the parameters.
Maybe it's easier for you to compile the C-Code (using your system
C-compiler) to a dll (or, since you seem to work on OSX) a shared object
file. Take a look at the gcc manual.
Then take a look at the doc of MATLAB for loadlibrary.

Titus

Subject: C to Matlab conversion

From: Rose Watchy

Date: 23 Jul, 2009 14:03:02

Message: 10 of 12

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h49h13$fvu$1@fred.mathworks.com>...
> "Julia Woody" <jwwoody0@gmail.com> wrote in message <h47mne$ot4$1@fred.mathworks.com>...
> > I want to convert a few C files to matlab, when I try to use mex function I am getting error :( So, I wil try to convert it page by page. One of those page is the following, can you help me by sending the matlab codes of the following codes:
> >
>
> Just a though but
> - making the MEX working is certainly easier or at least less tedious than converting C to Matlab.
> - I have not seen a single time where this board doing a free work to someone, even for a not-tedious one.
>
> Bruno

Then, may be you can help to be able to run the application at http://learnfmri.ucsd.edu/howto/imagesim.html This is an open source code, after the downloading when I try to run the imsim.m file then I am getting the following error:

??? Undefined
function or
variable 'fig'.

Error in ==>
imsim>InitializeIMSIM
at 75
    delete(fig);
    
Error in ==>
imsim at 26
feval(action,varargin{:})

What is the solution?

Subject: C to Matlab conversion

From: dpb

Date: 23 Jul, 2009 14:31:43

Message: 11 of 12

Steve Amphlett wrote:
...

> Irony?? This is just a case of someone not recognising a joke/leg-pull.

Well, I thought that rather ironic, meself...

--

Subject: C to Matlab conversion

From: Bruno Luong

Date: 23 Jul, 2009 15:12:00

Message: 12 of 12


> Then, may be you can help to be able to run the application at http://learnfmri.ucsd.edu/howto/imagesim.html This is an open source code, after the downloading when I try to run the imsim.m file then I am getting the following error:

Sure, no problem, just wait few minutes, me and "us" will do it for you. We will drop any work we are working and do it for you.

Bruno

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com