Running script from App designer, workspace not updated

Hello,
I am trying to run a script from App designer. This script defines variables based on files in a folder., the files are timeseries and it can vary how many files which are in the folder. When I run this script from the command window, all the variables are found in the Workspace afterwards. This is not the case when running it from the App designer. In the application there are other scripts depending on the variables from this script, hence if the variables exsisted in the workspace this would be an advantage. Due to the variation in the folder, I think it would be unwise to make a fixed number of outputs and converting the script into a function. Please let me know if you have any tips or ideas how I can make this work.
Thank you very much in advance.

2 Comments

"I think it would be unwise to make a fixed number of outputs and converting the script into a function."
Store all of the parameters in one structure and pass that variable.
"...if you have any tips"
Avoid scripts.
Thanks, I do could not agree more. Again, I was given the scripts and did recommend to rewrite them as functions.

Sign in to comment.

 Accepted Answer

If you are trying to view these just so you know they are being shows correctly, then you can enter debugging mode (very similar to debugging in a livescript) by clicking the '-' (on the left hand side of the code view) next to the line number directly after the line of code you are querying. This pauses the app code and all variables within the current function are displayed in the workspace.
If you are wanting to use these variables within Matlab (not App designer), then you can use the following at the top of the function within the app which contains what you want:
global ThingYouWant
% Replace 'ThingYouWant' with whatever variable you need to display.
Then you simply go to your command window, type exactly what you put in the app and the variable should show up in the workspace.
Let me know of any problems and I'll try my best to help.

4 Comments

Thank you for your response.
The main problem is that I have a script which declares many variables. These variables are used by other scripts. I do not want to include all these variables as outputs, but just have them in the workspace. Then, when I run the next script which defines new variables based on the inital ones I dont have to include them as inputs. The scripts uses variables from the workspace.
The main reason why I dont want to include a lot of inputs and outputs in all the scripts is because it is not a fixed number. I could make adjustment to the scripts so everything is saved in a 3-d matrix where the size is not fixed. However, this is not wanted, because I was handed all the scripts and they run perfectly.
So to sum up, instead of executing a script in the command window, I want to execute it in App designer. I do however, want all the delcared variables in the script to appear in the workspace.
Hope this clearifies things. Thank you again.
Have you tried turning these secondary script(s) into functions and calling on them within the app? This could be a way to get around the workspace issue. You'll need to define the variables you require in the function call but other than that you should be all good. That's all I can think of using to get around the workspace issue.
I'd recommend looking here for some basics on functions and then this is a simple way of recalling functions from another script (or in the app designer).
"I want to execute it in App designer. I do however, want all the delcared variables in the script to appear in the workspace."
Different tools are good at different things.
Scripts are a very basic tool for very basic code. They are not suitable for complex projects.
You are reaching (or most likely are already beyond) the limits of what is a reasonable to write using just scripts. For a start, that data handling sounds truly terrible (very fragile and difficult to test automatically).
Complex projects eventually require more complex approaches and tools. This is why functions and classes and workspaces and many other programming features exist: because at some point the complexity of a project requires more control than a simple script can deliver: input and output checking, independence, abstraction, asynchronous execution, expandability, testability, repeatability, debugging, etc. These features require a bit more effort to set up, but give you the power to achieve your complex project goals.
Refactoring the code is likely the much better choice in the long term.
"I do however, want all the delcared variables in the script to appear in the workspace."
Adding more fragile code on top of other badly-designed code is unlikely to be a good approach.
Thank you, rewriting all the scripts into functions and passing a struct between them.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!