Best practices for MATLAB code

Best practices for MATLAB code
Does exist in MATLAB code some directive like C #ifdef
#ifdef name
program text
#else
more program text
#endif
or just I use if instruction?
Thanks,
F.

2 件のコメント

Stephen23
Stephen23 2026 年 4 月 12 日 19:57
dpb
dpb 2026 年 4 月 12 日 21:37
To add, MATLAB does not implement any preprocessor directives, no.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2026 年 4 月 12 日 21:44

0 投票

There is no equivalent to the C preprocessor in MATLAB.
The C pre-processor can do some ugly things, such as
#ifdef __CPLUS
void strlen (
#else
if (fiddlesticks) {
#endif
that can completely change the meaning of the code
There is no MATLAB equivalent of that.
The closest you can get is to use something like
if exist('name', 'var')
but you cannot achive the wholesale corruption of the code the way you can in C or C++.

2 件のコメント

fabrizio restori
fabrizio restori 2026 年 4 月 12 日 22:31
Grazie
dpb
dpb 2026 年 4 月 13 日 12:22
編集済み: dpb 約17時間 前
"... you cannot achi[e]ve the wholesale corruption of the code ..."
Not to worry....you can still create mass confusion with intentional or accidental silent aliasing of MATLAB builtins... <grin>

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB Coder についてさらに検索

タグ

質問済み:

2026 年 4 月 12 日 19:12

編集済み:

dpb
約18時間 前

Community Treasure Hunt

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

Start Hunting!

Translated by