473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

on variadic function in C when porting matlab files to C

dd
Hi, all,

I found many limitation of C in the process of porting some matlab
files to C, but I'm going to stick to it this time. One problem is the
variadic function. C doesn't have overload
mechanism, right? And to use va_list and va_arg, etc. to realize the
variable
number of inputs to a function is OK, but I don't know how to express
the
missing variables in the function like below . Thank you very much if
anyone could help me out!

The matlab part is like below

function [output_firing_time, x,
y]=calculate_neuron(input_firing_times,delays,weight s,tau,threshold,sim_time)

disp_fire_info=0;

%Activation Threshold
if nargin < 5 || threshold==-1
threshold=2;
end
%Time constant for spike response function
if nargin < 4 || tau==-1
tau=2;
end
%Delays
if nargin < 3 || min(delays==-1)
delays=[1 1 1];
end
%Weights
if nargin < 2 || ~iscell(weights)
weights=[1 1 1];
end
%Input Firing Times
if nargin < 1 || min(input_firing_times==-1)
input_firing_times=[0 1 2];
end

output_firing_time=sim_time(3)+1;

The c part

/************************************************** *******/
*calculate_neuron(float *num_var,...)

{
va_list ap;
int count = 0;
float temp=numinputvar;
// to calculate the number of inputs
float x;
float ***y;
float output_firing_time;
float t_begin, t_interval,t_end;
float t_index[1000]=0;
float current_delay;
// int num_var=0;
int max=0;
int start_index=0;
// int num_inputs=0;
int j=1,i,k,n;
int indexdelay,index_input_firing;
int disp_fire_info=0;

va_start(ap,num_var);
//need to change, for input_firing times might be bigger than 100
// Basic Spiking Neural Network
while( temp != -10000.00000000000000 )
{
count++;
temp = va_arg( ap, float);
}
va_end( ap );

//Activation Threshold
if (num_var<5 || *threshold==-1)
*threshold=2;

//Time constant for spike response function
if (num_var<4 || *tau==-1)
*tau=2;
//delays
if (*delays==-1||*(delays+1)==-1||*(delays+2)==-1)
indexdelay=1;
if (num_var<3 ||indexdelay==1) // ||delays)
min(delays==-1) how to
port?
*delays=[1 1 1];
//weights

if (num_var<2 ) //~iscell(weights) ??
*weights=[1 1 1];
//Input Firing Times

if(*input_firing_times==-1||*(input_firing_times+1)==-1||*(input_firing_time
s+2)==-1)
index_input_firing=1;
if (num_var<1 || index_input_firing==1)
input_firing_times=[0 1 2];

Mar 28 '06 #1
2 1670

Hello,

I found many limitation of C in the process of porting some matlab
files to C, but I'm going to stick to it this time.


I don't have any spesific help/comments to your problem, but my
general answer is that attempts to translate (more or less) directly
matlab -> C is probably bound to give your large amounts of grief.

If you really have to do this I would strongly recommend thinking
carefully through the problem and the solution, and expressing it in a
way closer to the 'C' spirit (whatever that might be) than directly
translating the matlab code.

Good luck.

Joakim

--
Joakim Hove
hove AT ntnu.no /
Tlf: +47 (55 5)8 27 13 / Stabburveien 18
Fax: +47 (55 5)8 94 40 / N-5231 Paradis
http://www.ift.uib.no/~hove/ / 55 91 28 18 / 92 68 57 04
Mar 28 '06 #2

dd wrote:

The matlab part is like below

function [output_firing_time, x,
y]=calculate_neuron(input_firing_times,delays,weight s,tau,threshold,sim_time)

disp_fire_info=0;

%Activation Threshold
if nargin < 5 || threshold==-1
threshold=2;
end

Why not something like...?

void calculate_neuron(float num_var,...)
{
...
tau=-14;
threshold=10;
... some more defaults

va_start(ap,num_var);
switch(num_var)
{
case 2:
tau=va_arg(ap,float);
case 1:
threshold=va_arg(ap,float);
}
va_end(ap);

...
}

Mar 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ali | last post by:
How to use python in matlab?
89
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
5
by: Christopher Benson-Manica | last post by:
Do variadic functions (such as printf()) always scan the format string for format specifiers, even when there are no additional arguments? If it is instead a QoI issue, what would be true for a...
3
by: micromysore | last post by:
Hi, I want to post some code which has defn like struct AVPicture { int *data; int linesize; } the is noe recognised by matlab, so i need to port to some form like struct AVPicture { int...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
2
by: zipls | last post by:
suppose a simple matlab function //add.m function result=add(left,right) result=left + right; //end of add.m use matlab comtool to encapsulate the function in fun.dll and then use it in...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
4
by: itcecsa | last post by:
Hi, I am implementing a small Python project, what I am going to do is to open Matlab and run some M-files, and get some output from Matlab command prompt. I have no idea how to open Matlab...
1
by: chitralaxman | last post by:
Sir, I'm a M. E (comuter Science and Engineering) Student and now i'm doing my project in Bioinformatics. I'm new to perl & MATLab. I've written the code for neural network simulation in MATLab....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.