MATLAB: How to save the output variables of a MATLAB Script run in App Designer using evalin function into base workspace

app designerMATLAB

Hello MATLAB Enthusiasts,
I want to run a MATLAB Script say 'untitled.m' using inbuilt MATLAB function evalin from MATLAB App Designer environment
after running the script, I want my all the output variables of the script to be displayed in the base workspace. Can anyone please guide me on this?
Thanking You!

Best Answer

  • Before you evalin('base', 'untitled'), use evalin('base') to run a "whos" in the base workspace. Assign the result to a variable.
    Then run your evalin('base', 'untitled')
    Then again use evalin('base', 'whos') and assign the result to a different variable.
    Now take the two whos() results and compare them. Any variable that exists in the second result but not in the first is definitely an output of the script and can be displayed by using evalin('base') to display the value. For any variable that existed in both results, check to see if the sizes or types are different: if they are, then again the variable is an output variable.
    Now you are at the point of checking two variables in the same name and same size and same type, and you want to know whether the variable is an output variable or not. Unfortunately, if the sizes and types are the same, whos() cannot tell you that.
    So what you should do before running your 'untitled' script is something like use a serialization routine on each variable that exists in the base workspace at the time you start, and then do something like MD5 on the serialized bytes, and store the MD5 signature. Then you would so the same thing afterwards, and compare the MD5 signatures: if they are different, then the variable was an output variable.
    Unfortunately, having the same MD5 signature is not proof that the two values are the same. You could compare the serialized versions of them for differences.
    Might I suggest to you that it would be considerably easier if you were to instead use a function, rather than having to figure out after the fact which variables the script modified?