How to get var from base workspace in test sequence

How to get var from base workspace in test sequence

6 commentaires

Rik
Rik le 20 Août 2024
I would never advise the use of evalin, especially not in a tester.
What are you actually trying to achieve? The answer below answers your question, but I expect you should be asking a different question.
(also, if the answer solves your question, you should click the 'accept answer' button)
浩 程
浩 程 le 20 Août 2024
I want to use code to iterate a variable in a test sequence, which requires getting the change value from the workspace.
浩 程
浩 程 le 20 Août 2024
Or how can I use code in the testsequence to get the value of output
浩 程
浩 程 le 20 Août 2024
Thanks
Stephen23
Stephen23 le 20 Août 2024
Modifié(e) : Stephen23 le 20 Août 2024
"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 le 20 Août 2024
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.

Connectez-vous pour commenter.

 Réponse acceptée

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.

5 commentaires

浩 程
浩 程 le 20 Août 2024
Ok, thank you!
Is it possible to modify the value of the base workspace variable from TestSequence Block?
@Shubham, I am trying you solution but having this error
Rik
Rik le 15 Jan 2026
@Flavio Luiz Puhl Jr: once you're serious enough about what you're making that you're at the stage of code generation, you should rethink your strategy. This is a cludge solution. It works, but you shouldn't use it for anything that matters.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2021a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by