Azzera filtri
Azzera filtri

Matlab Coder: Avoiding that input variables are converted to constants

7 visualizzazioni (ultimi 30 giorni)
When generating C-code for this function, the resulting tinyplot.cpp creates the same output regardless of the input to the function. It somehow assumes that the calling function at code generation time will be the only function to ever call it. How do I force the input variables of tinyplot to remain input variables, so that it's generated plot depends on what inputs are used when calling tinyplot.cpp?
function tinyplot(dataVector,PlotWidth, PlotHeight)
% A vector of input data, 'dataVector', is plotted in the command window
% using dots. The plot size is scaled into 'PlotWidth' columns and
% 'PlotHeight' rows.
if nargin == 1
PlotWidth = 10;
PlotHeight = 10;
end
coder.inline('never');
overSizedFactor = length(dataVector)/PlotWidth;
dataMax = ceil(max(dataVector));
dataMin = floor(min(dataVector));
if dataMax>dataMin
dataVector_scaled = (dataVector-dataMin)/(dataMax-dataMin)*PlotHeight;
else
dataVector_scaled=dataVector;
end
bgMarker = ' ';
plotMarker = '.';
fprintf(1,repmat('_',1,PlotWidth));
for y=1:PlotHeight
fprintf(1,'\n');
for x=1:PlotWidth
combineWhichVectorCells = uint32(1+floor((x-1)*overSizedFactor)):...
uint32( floor((x-0)*overSizedFactor));
value = mean(dataVector_scaled(combineWhichVectorCells));
if value >= PlotHeight-y
if value < PlotHeight-y+1
fprintf(1,plotMarker);
else
fprintf(1,bgMarker);
end
else
fprintf(1,bgMarker);
end
end
end
fprintf(1,['\n',repmat('_',1,PlotWidth),'\n']);
if ~coder.target('MATLAB')
coder.ceval('std::cin.get');
end
end

Risposte (1)

Ryan Livingston
Ryan Livingston il 16 Mag 2014
I assume that you are generating code for another function which calls tinyplot. Please correct me if I am wrong. If you would like to be able to call tinyplot in your generated code you could use it as the entry-point function like:
codegen tinyplot -args {1:10,1,1} -report
Alternatively, in the function that calls tinyplot are the arguments all constants such as:
function foo()
tinyplot(1:10,10,10);
If so you could pass in the top-level input arguments:
function foo(a,b,c)
tinyplot(a,b,c);
codegen foo -args {1:10,1,1}
Since a,b,c are all arguments to the entry-point function, the call to tinyplot will not include constants for the arguments.
If neither of those resolve it for you, it would be helpful to know how you are generating code for tinyplot and related functions. What does your codegen command look like or how has your Coder project been set up?

Categorie

Scopri di più su Generating Code in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by