I imported some data and them cleaned it up, there is a lot of data so this is quite time consuming.
I then wrote a scipt that uses these variables.
However when I went to run the script, it says that these varibles are not know. In the workspace editor is only shows variables declared in the script.
Q1.) Is there a way to get the original variables back?
Secondly as the clean up operation takes quite some time I don't want to have to import that data and clean in every time I run the M-file.
Q2.) So once I have the cleaned data how do I make these variables available to an M file (do I have to declare them as global or something like that?)
To be clear I tried to just debug the script rather than running it from the command window, I just wnat to get the base variables back now if possible!
ahem there was a errant clear used in the script that's why all the variables were disappearing.
A misplaced Clear or Clear all may be the problem. Similar thing happened to me once.
Related
I was trying to save my Matlab variables and environment into a session so that next time I can directly load them without repeating the codes. I know how to save the Workspace variables but their way of saving a session doesn't work. It's said to be File -> Save to a session. But I couldn't find the button "File".
Any thoughts?
OK Actually I figured out an alternative solution. I realized that I could save all the Workspace variables. But my variables are too huge. So I ended up saving all my commands in a .m script file.
So next time when I want to resume my work, I just type the name of that script file to run all the useful commands to create the working variables and set up the script paths I need.
I wrote some script called drawCurves.m to draw some curves. Then I called this script via publish function:
publish('drawCurves.m', 'outputDir', destPath, 'showCode', false)
Unfortunately, no any breakpoints set inside drawCurves trigger. If I call script directly by name, breakpoints do trigger.
Is it possible to fix somehow?
The publish command calls a private function evalmxdom to actually run the code in your file. You can find evalmxdom at $matlabroot%\toolbox\matlab\codetools\private\evalmxdom.m, where $matlabroot$ is your MATLAB installation directory.
If you read through it, you'll find a section at around line 60 where it stores the current breakpoints, turns them all off, and then sets things up so that the original breakpoints are restored when publishing is finished.
You'll notice that the code calls a subfunction safeDbclear that clears the breakpoints. Try commenting out the contents of that subfunction, and publishing again.
NB:
I'm on R2017a: if you're on a different version and this file has changed between versions, the line numbers may be different.
Be careful: you will be modifying files that are part of your MATLAB installation here. Take a backup of the file before you make a change to it.
This may well mess up some aspects of publishing - it's turning off breakpoints for a reason.
I wish to know, if there is a way to force Matlab to retain all historically placed breakpoints -red dots which enable code debugging- in the Matlab Editor/Debugger inside functions, classes, etc. from one session to another, for example, and without being deleted with clear all commands.
It would be easy for debugging huge pieces of software while changes are introduced, and because Matlab sometimes simply shut down because of internal errors.
Thanks fellows.
dbstop is the cleaner solution. Just insert it in the place you want the debugging to stop and this will not be removed until you edit or comment the line.
You need to save the breakpoints and reload them in next session. You can use dbstatus to get a structure that contains information about all breakpoints and save it into a file:
s = dbstatus('-completenames');
save FILENAME s
and later retrieve them using dbstop
load FILENAME
dbstop(s);
You can automate it by including it in startup.m and finish.m files (create them on default user path if they don't exist).
I would like to update variable editor at a predefined interval during a running script without having to use a break. Is this possible? I have a sim that runs for hours, I would like to be able to come back every hour and grab some values off a matrix in variable editor to play with in excel without interrupting running script. Any ideas would be greatly appreciated.
I think using assignin to copy your matrix to the base workspace should do exactly what you want. You'd need to manually reopen the variable in the editor to reflect the new data if it's changed.
If you wanted to get fancier, I imagine you could script evalin and openvar to do it for you, but I no longer have real Matlab to test with and Octave's fledgling GUI isn't there yet.
I need to create a matlab mfile that will run another matlab file with default values given in a txt file. It's ment to be useful for testing programs, so that user may specify values in a txt files and instead of inputing values every time he starts the program, my script will give the program default values and user will only see the result.
My idea is to load tested file into a variable, change 'variable=input('...');' for variable = default_variable;, save it to tmp file, execute, and than delete tmp file. Is this going to do the job?
I have only two problems:
1) How to eliminate the problem of duplicated variable names - i mean this must work for all scripts, i don't know the names of variables used in tested script.
2) As I wrote before - is this going to work fine? Or maybe I missed a easier way to do it - for example maybe I don't have to create a tmp file?
I really need your help!
Thanks in advance!
If the person who has to edit the default values has access to Matlab, I would recommend saveing the values in a mat file and loading them when needed. Otherwise you could just write a smalls cript that contains the assignment to certain variables, but make sure to keep this small. For example:
maxRuns = 100;
clusters = 12;
So much for setting up the defaults. Regarding the process my main advice is to wrap the thing that you want to test into a function. This way variables used in the code to call the 'script' will not interfere as a function gets its own separate workspace. Check doc function if you are not familiar with them.