Adding #ifdef to the generated C code
30 views (last 30 days)
Show older comments
Priya Tejankar on 7 Jan 2020
Answered: Rajat Tewari on 10 Jan 2020
I am developing code in MATLAB (m script) and need something like #ifdef to decide whether to execute a function during compilation.
Does something like #ifdef exist for m-script ?
Rajat Tewari on 10 Jan 2020
You can use exist function for this process along with if else statements to achieve your goal in .m file:
Refer to exist documentation. This is a example of the same for checking if a variable is in workspace or not.
% if variable exists in the workspace
if exist('a') == 0
% if variable doesn't exists in the workspace
elseif exist('a') == 1
The same can be checked for files as well.
Hope it helps.
More Answers (0)
Find more on Loops and Conditional Statements 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!