How can I avoid a redundant for-loop in generated code that computes the virtually unused quantity 'trueCount'?
Show older comments
For the following lines:
stopEdgeIdx = stopEdgeIdx(stopEdgeIdx <= globalMaxIndx);
if ~isempty(stopEdgeIdx)
<< do something >>
end
The generated C code contains two loops, which seems redundant:
k = trueCount - 1;
trueCount = 0;
for (b_i = 0; b_i <= k; b_i++) {
if (stopEdgeIdx_data[b_i] <= globalMaxIndx) {
trueCount++;
}
}
partialTrueCount = 0;
for (b_i = 0; b_i <= k; b_i++) {
if (stopEdgeIdx_data[b_i] <= globalMaxIndx) {
stopEdgeIdx_data[partialTrueCount] = stopEdgeIdx_data[b_i];
partialTrueCount++;
}
}
Is there a way to have only one loop instead of two?
Accepted Answer
More Answers (0)
Categories
Find more on Function Definition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!