Edit
As of MATLAB R2018b you can use the coder.EmbeddedCodeConfig setting ColumnLimit to control line wrapping in the generated code with MATLAB Coder and Embedded Coder. For older realeases read below.
Original Answer
There isn't a built-in way of doing this. I've made a note of this request so our team can consider adding such functionality in future releases.
For now a workaround could be to use an external code formatting tool. clang-format is quick to invoke and highly configurable. The Coder config setting PostCodeGenCommand allows you to run some MATLAB code after code generation finishes but before the C/C++ compiler runs. So you can use that to call clang-format.
- Make the file doclangformat.m:
function doclangformat(buildInfo)
sourceFiles = join(buildInfo.getSourceFiles(true,true));
sourceFiles = sourceFiles{1};
cmd = ['clang-format -i -style=''{BasedOnStyle: LLVM, ColumnLimit: 20}'' ' sourceFiles];
system(cmd);
I've set ColumnLimit to 20 so the effect is obvious. The code will be drastically wrapped. You can view the other options in the clang-format documentation. - Set up the MATLAB Coder or Simulink Coder configuration and generate code
MATLAB Coder
cfg = coder.config('lib');
cfg.PostCodeGenCommand = 'doclangformat(buildInfo)';
codegen foo -config cfg <other codegen args>
Simulink Coder
Now you should see that your code is wrapped to about 20 columns.
The main downside of this approach is that the other Coder style settings like IndentStyle, IndentSize, etc. will need to be specified in your clang-format specification.