Matlab – Without GUI – Part 1.5/2

I said I would return in a week or so to talk about my experiences with using Matlab without a GUI in part 1/2 of this series. I also said I would get back with a report on how debugging works in a command line environment because it could be pretty important for a lot of us. But it seems Matlab has a pretty good setup to debug using the command line. This is just awesome and I am so happy.

With the following commands, you will be well setup to do some basic debugging. You can refer the help docs for your specific needs. This will give you a quick review of what you can do.

Set breakpoints at different places in the script using dbstop. Mention the script name and the line number where you need to stop, using the following line of code on the command line. dbstop in scriptname at linenumber

Look at all the places you have used a breakpoint using, dbstatus. Just type in dbstatus in the command line and it will let you know.

When you are running the program, it would stop at the places where you have added breakpoints. When you are done analyzing your variables and what not, you can type in dbcont to continue execution until it encounters the next breakpoint, or the end of the program.

You can use dbstep to step one line at a time just like how you would with the GUI. You can also say something like dbstep 5 to step through five lines of code.

Remove breakpoints in a line or, all of it in a file or, all of it in all files using dbclear. dbclear all will clear all of it in all places. dbclear in script/filename will clear all breakpoints in a file. You can also add line number to remove something specific from a specific place.

Last, use dbquit to exit debugging mode.

For more interesting ways to debug, take a look at the help files. They have a load of information along with examples. You can use some of these commands with an if statement. Like for example, adding a break point when some condition is satisfied. This could be very useful. A lot of actual debugging does happen this way when you are working with a lot of code. Happy debugging.

It has not been one week yet. So I named this post 1.5/2. You can only really get a good picture of things over time. So it is not just a sensation but rather the actual fact. I will be back again in a week or so with my conclusions.

Advertisements

Matlab – Without GUI – Part 1/2

Matlab can be invoked without its GUI on linux systems by typing in the following on the terminal.

matlab -nodesktop

This opens up matlab just like an Octave or Python prompt on the terminal. What is the use you may ask. You might be perfectly happy with the IDE like environment. But personally, there is something nice about using the terminal. Less fuss and more work. Makes you feel at home. If you are like me. Then you should try it.

I can use vim to edit my scripts. I can run my matlab scripts by typing in run scriptname.m. I can see all the variables by typing in who. I can see all the details of the variables by typing in whos. It gives me the type, shape and name of the variables. I can just type in the name of the variable to print it out.

Wouldn’t that be ‘a lot’ of what we would require? It feels really similar to using python scripts with scipy and numpy packages for signal processing. Sometimes I am using vim even when i am using the Matlab GUI as well. I use the gui just to run the code and look at the variables.

Wouldn’t it be possible to just use a text editor and then run the code alone on the terminal without starting up matlab in the first place? Yeah, technically Yes, with some other arguments you can do that. But every time you run it, matlab seems to load everything and you’d probably have to wait ten to twenty seconds for an output. That is not efficient.

Yeah, line by line debugging would also be really helpful sometimes. I will see if there are any workarounds for that, by the time i write part 2 of this blog. I will work with this for a week or so and get back with some updates about whether I am going to continue using it this way.

Mount a disk – Linux – cmd

To mount a disk (usually a file system that you usually go and click on using nautilus/caja (file browsers)) from the command line, use the following,

udisksctl mount -b /dev/disk/by-label/

Listing the content of /dev/disk/by-label/ will give you the names of the mountable disks/drives. Usually flash drives are mounted automatically so they do not have to be mounted. Unless you unmount it and want to mount it again. Use man udisksctl for more information. Also, I think it is udisks in some distributions.

Wget – Download from a list

If everyone started to read the manual then bloggers like me would…. eh no… I would still blog even if no one reads this.

This is pretty simple but it is really nice and may inspire you to investigate more. If you have a list of links to download all you have to do is put them all in a text file. One in each line. Then fire up wget from the terminal like this

wget -i path/to/textfile

 

This will download all of those files one by one and save it in the present working directory. Really good if you already have a list of links to download. Or if you have a set of links to download from on  the same page you can use some download plug in like downthemall on firefox.

You can use wget to do a lot lot more. Read the manual. You can use wget on bash scripts as well, since it is a command line tool. Imagine the possibilities. You could write a bash script with regex to get all files with certain patterns from a particular location. I once downloaded a full website containing more than a 1000 html pages with wget, and it was really good. But that was simple. Not much scripting involved though. You just have to look for the proper parameters to use with wget.

Get rid of the FAT(32)

Here is one good reason why you can stop using FAT32 file format for your drives.

The Story: I have been using computers since around 2000. I started out with windows 98 first of all and I have grown up using FAT32 for a very long time. When NTFS came in, right about when windows NT came in i guess? I am not sure, I never bothered to know what it was about and I continued using FAT32 on all my data drives till now. Although my C drive may have been in the new NTFS format, I was still using FAT32 for the other drives without realizing what I was doing. Then I switched to Linux where it was ext4. So for a lot of years NTFS and FAT32 did not bother me.

The Crux: Calamity struck now after so many years. I was trying to download an 8GB zip file containing a database and the downloads kept stopping at 4GB. A little investigation, and I came to know that the maximum file size in a FAT32 drive is only 4GB. Gladly, my trust wget command line downloader gave me a perfect error to search for. The only way out of this was to have an NTFS or ext4 drive. Maybe I would just go for ext 4. I dont see myself adding/installing windows anytime in the future on my laptop.

A good job for tomorrow. Backup everything on an external hard drive, format my hard disk, put it all back again.


Thu Oct 5 14:10:16 IST 2017: Related update here

Screen Record, on Linux

This is a quick way to make a tutorial or how-to video for someone. On my fedora, I already had this command line app called, recordmydesktop and it works well.

All you have to do is head to the command line and say recordmydesktop test.ogv. This will record the screen and save it to a file called test.ogv. To end recording, you can hit Ctrl + c.  It takes some time to process the file and save it. You might see something like the image below.

record

There a lot of options, including ways to specify an area of the screen to record and things like adding a short delay before it starts recording. Check out the man page (man recordmydesktop) for more details.

This records in OGV format. But you can quite easily convert it to an mp4 file, if you’d like, with ffmpeg or some other conversion software. With ffmpeg, use the following command.

ffmpeg -i test.ogv -c:v libx264 -preset veryslow -crf 22 -c:a libmp3lame -qscale:a 2 -ac 2 -ar 44100 output.mp4

I’m not sure if this is default or it got installed along with some other package. Anyway, installation is as simple as, dnf install recordmydesktop, as a root user. Happy recording.