How to get var from base workspace in test sequence

16 ビュー (過去 30 日間)
浩 程
浩 程 2024 年 8 月 20 日
コメント済み: Walter Roberson 2024 年 9 月 1 日
How to get var from base workspace in test sequence
  6 件のコメント
Stephen23
Stephen23 2024 年 8 月 20 日
編集済み: Stephen23 2024 年 8 月 20 日
"I want to use code to iterate a variable in a test sequence, which requires getting the change value from the workspace."
Pass it as an argument.
The approach you are attempting has a very strong smell to it: https://en.wikipedia.org/wiki/Code_smell
Rik
Rik 2024 年 8 月 20 日
Why don't you supply the list of test variables in a cell array?
Making your test cases static helps keeping your tests stable. Without a consistent test, it is not possible to have a good regression test.

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

採用された回答

Shubham
Shubham 2024 年 8 月 20 日
In MATLAB, if you want to access a variable from the base workspace within a Test Sequence block, you can use the evalin function. The evalin function allows you to evaluate an expression in a specific workspace, such as the 'base' workspace. Here's how you can use it in a test sequence:
  1. Double-click on your Test Sequence block to open the Test Sequence Editor.
  2. You can use the evalin function in your test sequence actions to retrieve the value of a variable from the base workspace. The syntax is as follows:
varName = evalin('base', 'variableName');
Replace 'variableName' with the name of the variable you want to access.
3. Suppose you have a variable named threshold in the base workspace and you want to use it in your test sequence. You would write:
thresholdValue = evalin('base', 'threshold');
Remember that using evalin can make your test sequences dependent on the state of the base workspace, which might affect reproducibility and clarity.
  3 件のコメント
Tanmay
Tanmay 2024 年 9 月 1 日
Is it possible to modify the value of the base workspace variable from TestSequence Block?
Walter Roberson
Walter Roberson 2024 年 9 月 1 日

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by