Running script from App designer, workspace not updated
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Erik Vabo Vatsvaag
il 13 Gen 2021
Commentato: Erik Vabo Vatsvaag
il 19 Gen 2021
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 Commenti
Risposta accettata
Daniel Catton
il 13 Gen 2021
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 Commenti
Stephen23
il 15 Gen 2021
"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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!