Unable to locate a C-compiler required by Stateflow and MATLAB Function blocks. Use 'mex -setup' to select a supported C-compiler.
Show older comments
I'm trying to use Matlab function. When I finish my simulation and click 'run' there is an error "Unable to locate a C-compiler required by Stateflow and MATLAB Function blocks. Use 'mex -setup' to select a supported C-compiler." I have no idea where is the 'mex-setup'. Could you fix that to me. Thanks in advance! Sorry with some mistakes in grammar. I'm not a native
Accepted Answer
More Answers (4)
Tu Tran
on 3 Jun 2018
0 votes
1 Comment
Walter Roberson
on 3 Jun 2018
Which MATLAB release are you using?
You should be able to use MATLAB provided that your release indicates it is available for Windows 7, and provided that you have SP1 or later
Tu Tran
on 3 Jun 2018
0 votes
1 Comment
Walter Roberson
on 3 Jun 2018
You can use Windows SDK 7.1 for that version.
Tu Tran
on 8 Jun 2018
0 votes
8 Comments
Walter Roberson
on 8 Jun 2018
That usually indicates there was an error in generating the model. It would normally have displayed a bunch of lines before that showing the compilation process, and those lines give information about what worked or failed.
Tu Tran
on 8 Jun 2018
Walter Roberson
on 8 Jun 2018
DTC_sfun is automatically created for a model named DTC . Do not worry about the fact that it does not already exist: when you fix your model, MATLAB will create DTC_sfun
Tu Tran
on 8 Jun 2018
Walter Roberson
on 8 Jun 2018
The only thing I see at the moment is that Code Generation stops immediately because your model contains discrete items (switches) but has been configured for a continuous solver. Changing to a discrete solver solves that difficulty.
What action are you taking at the time you get the error about DTC_sfun ?
Walter Roberson
on 8 Jun 2018
You should run the Upgrade Advisor, paying attention in particular to Simplified Initialization and "Check Usage of Outport Blocks". I am seeing cases of,
"Since the outport has an undefined 'Initial output' value and at least one of the sources of the outport is not a valid source to inherit the initial value, the outport uses the default ground value as the initial output."
You also have other difficulties related to the matter of whether to use continuous or discrete simulation. Some of your blocks expect continuous integration, which requires that one of the ode*() functions be run on your behalf to predict the outputs over finite steps. The Model Advisor recommends that you run discretization on your system.
To emphasize: using relays and switches is not theoretically compatible with continuous simulation, since relays and switches have discontinuous outputs and that cannot be modeled by any equation solver.
Tu Tran
on 8 Jun 2018
Walter Roberson
on 8 Jun 2018
It is not possible to just switch to discrete solver: you also need to discretize the model.
I am having some difficulties getting the powergui library block to interface properly -- but that is a number of steps further than you are getting.
There should be a number of lines of output before the message about DTC_sfun: please post those.
Also, please remind me which MATLAB version you are using.
Tu Tran
on 13 Jun 2018
Edited: Walter Roberson
on 13 Jun 2018
Categories
Find more on Simulink Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!