Hi all.
I ve been using Matlab for quite some time now and recently I ve decided to link
a script in C that can be called from the Matlab environment.The code works fine,
ouputs the right results but there is a thing about the memory management :it just takes too
long!Inside the C code there are 3 nested for loops that under normal coditions (i.e. in a pure C framework ) there would be no latency at all ( at least i think so..).
I ve done some searching on memory control in C ( i use mxCalloc() to dynamically allocate memory space) but the delay persists.I think that Matlab always includes some delay when
there are calls to external functions,i.e no Matlab's built in ones.
If anyone has successfuly managed to call a C script via Matlab plz reply coz my debugging has reached its limits..no apparent reason for this undesirable slowing down.
Thx
Depending on the loops, this can take a LONG time. To get a rough idea of how many processes you are performing, multiply the three ranges together. Then multiply by the number of lines of code within the loop to get an idea of the effective size of your program. "just 3 nested for loops" can be a tremendous amount of processing time.
thx anyways panther but lemme put it that way:
suppose a have a variable (double) and a certain array of doubles.
I can get rid of the innermost loop if i can write some lines that
compare the double variable with each of the array elements and
return the index of that element whose subtract from the variable is the
minimum for the whole array.That is,I want to know which matrix value
is closest to this specific original double value i have as an input here.
That would spare me this last loop and relieve the whole code of
the main computational burden (now,the main math calculation on doubles
take place just there).I dont know how i could do that without a loop.
In Matlab, coding is just 2 lines of code but in C?
Any help appreciated
It's a similar number of lines in C. I'm not familiar with Matlab, however, so I don't know how much help I'll be.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks