Matlab to C code conversion issue
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
anshuman mishra
le 14 Août 2019
Réponse apportée : Steven Lord
le 14 Août 2019
function final_seq=myapp(x,y,a,b,i,j,z,k,p,m,new,xt,J,ix,X1,final_seq)
x=input(' Enter fast clock ratio '); %fast clock
y=input(' Enter slow clock ratio '); %slow clock
................
end
when i try to compile the above code in matlab coder,following error pops up:
" input is not supported for code generation"
What is the work around this issues.Please help its urgent
0 commentaires
Réponse acceptée
Mukund Sankaran
le 14 Août 2019
There is unfortunately no code generation support for the input function as of MATLAB R2019a. We've made an internal note of your request so we can look at lifting that limitation in the future.
In the interim, here is a potential workaround -
function y = foo
y = input_codegen('Enter a number: ');
fprintf('Read: %s\n',y);
end
function resp = input_codegen(prompt)
%#codegen
coder.extrinsic('input');
if coder.target('MEX') || coder.target('MATLAB') || coder.target('Sfun')
resp = input(prompt, 's');
else
coder.cinclude('<stdio.h>');
fprintf('%s',prompt);
cresp = char(zeros(1,1024));
coder.ceval('fgets',coder.ref(cresp(1)), 1023, coder.opaque('FILE*','stdin'));
% Call strlen in C and trim output
slen = int32(1);
slen = coder.ceval('strlen',coder.rref(cresp(1)));
resp = cresp(1:slen);
end
end
0 commentaires
Plus de réponses (1)
Steven Lord
le 14 Août 2019
function final_seq=myapp(x,y,a,b,i,j,z,k,p,m,new,xt,J,ix,X1,final_seq)
x=input(' Enter fast clock ratio '); %fast clock
y=input(' Enter slow clock ratio '); %slow clock
x and y are the first two inputs to your function, but your input calls are throwing away those first two inputs to replace them with the user-entered data. Why not just have the code that calls your generated function pass x and y into your function directly and eliminate input?
0 commentaires
Voir également
Catégories
En savoir plus sur MATLAB Coder dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!