Does matlab application provide any suggestion for converting a script into function?

2 ビュー (過去 30 日間)
Atin
Atin 2023 年 1 月 18 日
移動済み: dpb 2023 年 1 月 18 日
For converting matlab scripts into functions, one have to check which variables do not have fixed value and can be converted into input parameters.
Is there any possible way for MATLAB to suggest this to the user? A way to get a list of variables and their assigned values from the script, which can then be manually inspected.
  1 件のコメント
John D'Errico
John D'Errico 2023 年 1 月 18 日
Ugh. No. There is no automatic way to do this, since one script might execute another script, or call functions which do all sorts of strange things, creating variables in your workspace on the fly.
How do you do it?
Rule 1: DON'T USE SCRIPTS. Learn to start writing functions.
Rule 2: See rule 1.

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

回答 (1 件)

dpb
dpb 2023 年 1 月 18 日
移動済み: dpb 2023 年 1 月 18 日
If you just add the function...end wrapper and execute, you'll find each undefined variable in turn...of course, it would be more efficient to at least do an initial cursory examination.
One could start with rudimentary grep pattern searches for assignment statements, etc., ...

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by