Problem converting Matlab code to C standalone executable using Matlab Coder
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hank
il 3 Set 2012
Commentato: Prachi Singh
il 25 Mar 2015
Hello, I am trying to convert a very simple Matlab program (connect two input strings together) to a C standalone executable using Matlab Coder.
The m file I have is:
function r = connect(a,b) %#codegen
assert(isa(a,'char'));
assert(isa(b,'char'));
r = [a,b];
The main.c I have is:
#include <stdio.h>
#include <stdlib.h>
#include "connect.h"
#include "connect_initialize.h"
#include "connect_terminate.h"
int main(int argc, char *argv[])
{
connect_initialize();
printf("Result is %s\n", connect(argv[1],argv[2]));
connect_terminate();
return 0;
}
The error message I got is:
26 C:\C\connect\main.c(16) : warning C4047: 'function' : 'char_T' differs in levels of indirection from 'char *'
27 C:\C\connect\main.c(16) : warning C4024: 'connect' : different types for formal and actual parameter 1
28 C:\C\connect\main.c(16) : warning C4047: 'function' : 'char_T' differs in levels of indirection from 'char *'
29 C:\C\connect\main.c(16) : warning C4024: 'connect' : different types for formal and actual parameter 2
I'd really appreciate it if somebody can give me a hint. Thanks.
3 Commenti
Prachi Singh
il 25 Mar 2015
I am also facing a problem while matlab to c conversion. I am working on ECG Analysis using Pan-Tompkins Algorithm I have a function defined as function [ ecg_m,qrs_amp_raw,qrs_i_raw,delay]= pan_tompkin(ecg,fs,gr) but after converting to c using matlab coder I am getting a function void pan_e(const emxArray_real_T *ecg, real_T fs, real_T gr, emxArray_real_T *ecg_m, real_T *delay)
and there is no a mention of qrs_amp_raw,qrs_i_raw which are mainly needed for further processing. Can someone suggest why this problem is occurring?
Risposta accettata
Kaustubha Govind
il 4 Set 2012
Modificato: Kaustubha Govind
il 4 Set 2012
I think you will find this MATLAB Coder demo useful. To be able to pass in a char buffer, I believe you also need to assert on the length:
function r = connect(a,b) %#codegen
assert(isa(a,'char'));
assert(size(a, 1) <= 1024);
assert(isa(b,'char'));
assert(size(b, 1) <= 1024);
r = [a,b];
Note that the generated prototype also expects the length of the strings to be passed in:
extern void myconnect(const char_T a_data[1024], const int32_T a_size[1], const char_T b_data[1024], const int32_T b_size[1], char_T r_data[2048], int32_T r_size[2]);
8 Commenti
Walter Roberson
il 7 Set 2012
Well that's a pain! No input functions at all, and the only output function is disp(). You are probably going to have to use coder.ceval()
Più risposte (1)
Walter Roberson
il 3 Set 2012
That C function signature corresponds to passing a single character to "a" and a single character to "b" and (I think) passing in a pointer to an array of exactly 2 characters to write "r" into.
Note: C expects "strings" to be null terminated, and so a C string with 2 usable characters would need 3 positions, the third for the 0 that terminates it. But it is not an error to construct a character array with only exactly 2 non-zero characters, as long as you do not treat it as a string. But in that code, you do try to treat it as a string, as you want to pass the result directly to printf(). One problem with that -- the function does not return anything and instead writes into an address you pass in in the third parameter.
I do not know why the code is expecting single characters instead of character arrays -- the assert() you are using would normally be suitable for character arrays. You probably need to do something different to alert codegen that you are not working with scalars. I speculate that you will need to initialize r to an array that is the maximum size of the string you will return.
15 Commenti
Walter Roberson
il 4 Set 2012
It appears that the following is relevant: http://www.mathworks.com/help/toolbox/eml/ug/br_jxhp.html
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!