How do I use fprintf with MATLAB Coder?
Mostra commenti meno recenti
I'm trying to use fprintf with MATLAB Coder but struggling to understand the limitation of "The formatSpec parameter must be constant."
I'm simply trying to save an array as an CSV or text file, and using the following code/function:
function write2CSV(varname, fname)
% Writes a particular variable to CSV file.
if nargin<2, fname = 'test.csv';end
fileID = fopen(fname,'w');
%fprintf(fileID,'%7.4f\n',varname);
fprintf(fileID,"%c\n",varname);
fclose(fileID);
You can call this function inside a script with any simple array as input such as:
write2CSV([1;2;3;4;5]);
It works fine in basic MATLAB. But when I try to generate C-code using MATLAB Coder, the specific error I'm getting is ... "argument corresponding to conversion character 'c' in the formatspec parameter is not scalar. It has to be fixed size scalar". HOW DO I SPECIFY A FIXED-SIZE SCALAR IN THE FORMAT SPEC?
I have tried various combinations for the format spec, but don't understand how to make it a 'constant'.
Any ideas? thanks a bunch!
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su MATLAB Coder in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!