How to Retrieve Data From Matlab Figures

I was using MATLAB to make several figures and I had saved them in the “.fig” format. A while later I misplaced the original data and I wanted to see if I could regain access to the data from the figure file. It took me a while and I had to dig pretty deep to find it but I finally found it and I’m posting it here to hopefully help you.

First click on your figure. Then go to the Matlab command line and type in the following commands.
line_handles = get(gca,'children')

x = get(line_handles(1),'xdata');          
%(1) is for first data line, (2) for second, etc.
y = get(line_handles(1),'ydata');

And viola you’ve gotten your x and y data back from any of your line plots on that figure. If you have subplots it works as well just be sure to click on the subplot plot that you want to get the data on before you enter the commands above.

Posted in Uncategorized | Leave a comment

Upgrading Your Kernel – The First Thing You Should Do After Installing Linux

Whether you are installing linux for you desktop or for your server, the first thing you should do after installation is update your kernel. You kernel is the backbone of Linux and updating it to the latest version will help ensure that all of your computer’s hardware will work with Linux. If you have a newer computer this could be vital to ensuring that the features of that computer are fully enabled. For example backlight keyboards, new Intel CPU features, wireless cards, better solid state drive access times, could all be held back in your new computer because the Linux kernel on your computer is too outdated to implement those features.

You can check to see what version of the the Linux Kernel you have by typing the following command into the terminal:

uname -r

In my case I have 3.8.0-19-generic. Once I see that I can go to the website kernel.org which lists the latest version of Linux. I can see that the 3.9.9 version is out as a stable version.

From here I have two choices. I can either download and compile the kernel (advanced) or find someone who has compiled the kernel for my Linux Architecture. I am using Linux Mint 15 so I searched google for “Linux Mint 15 64 bit Kernel 3.9.9″ and I promptly found this article with instructions.

Installing the Kernel in Mint/Ubuntu/Debian

If you’re using a Debian based 64 bit architecture (Mint, Ubuntu, and Debaian 64 bit Linux Distributions) you can get the 3.9.9 kernel files with the following terminal commands.


wget -c kernel.ubuntu.com/~kernel-ppa/mainline/v3.9.9-saucy/linux-headers-3.9.9-030909_3.9.9-030909.201307031551_all.deb
wget -c kernel.ubuntu.com/~kernel-ppa/mainline/v3.9.9-saucy/linux-headers-3.9.9-030909-generic_3.9.9-030909.201307031551_amd64.deb
wget -c kernel.ubuntu.com/~kernel-ppa/mainline/v3.9.9-saucy/linux-image-3.9.9-030909-generic_3.9.9-030909.201307031551_amd64.deb

These commands get the necessary files to upgrade the kernel. To install the kernel run the command


sudo dpkg -i *.deb

This installs the kernel. To try the kernel out restart your computer. Now when you type the command


uname -r

You should see the new version listed. For me updateing the kernel had one immediately noticable effect. My fn + f5 ad fn + f6 screen brighness keyboard combinations now work. A couple years ago updating the kernel allowed my new wireless card to work.

If you dual boot your computer you should be the GRUB bootloader menu with the undated kernel version. From grub you can also boot into “Previous Versions of Linux” to get your old kernel back. If something went wrong and the kernel doesn’t work well it is easy to rool your computer back. You can use the synaptic package manage/software manager to remove the kernel. Just search for the kernel version and mark for un-install.

Thank you Linus (the guy who invented the Linux Kernel).

Posted in Everything Penguin Related | Leave a comment

Fiberglassing a Rocket

Back in April 2011 myself and a friend bought a Forte Rocket kit from Apogee Rockets to complete my level one and two NAR certification flight. The kit used standard cardboard tubing and through wall fins. After spending the time putting the kit together, I decided to go the extra mile and fiberglass the rocket. I’m writing this to give a quick tutorial on fiberglassing rockets and tell you about the lessons that I learned from the experience.

Once I had the rocket completed I decided to go to Autozone and but some of the fiberglass. I bought:

  • 3m fiberglass cloth (8 square ft/.75 square m) $10
  • 3m fiberglass resin (32 oz/1 liter) $22.50

Knowing how much fiberglass cloth and resin you need is a challenge. I bought 8 square feet for my rocket, which was just enough to double layer the 3.5 ft tall cardboard tube and fin section of the rocket. I only ended up using about 60% of the 32 oz resin.

To apply the fiberglass, I used some good quality rubber gloves, foam paint brushes, and an object for squeegeeing the resin. The foam brushes did dissolve in the resin and sometimes left little bits and pieces behind. If you have an old paint brush you don’t mind throwing away it would be a better application tool. For the gloves, I suggest getting the good quality rubber gloves. The fiberglass resin will eat through latex gloves and many of the other thin gloves. If you are careful with the rubber gloves and don’t allow the fingers to cure together, then they will be in good condition after use with the exception of small area of resin hardened on the outside. For the squeegee, I used an old plastic card as a squeegee. It worked great.

When you mix the resin I suggest using a cheap glass cup. I originally used wax dixie cups, but the resin ate through them (probably because of the heat). Keep in mind that as the resin cures it gets hot. Mix enough resin to complete the fiberglass sheet you are working on.

Be sure that the area you are working in is well shielded with cardboard. If a drop of resin fall on a concrete floor and cures, it will be there for the eternity of time. Also wear pants and a long sleeve shit that you don’t care about. The resin will get on your clothes.

To allow the resin to cure faster you may be interested in using a heater. The resin usually takes 24 hours to completely cure, but by using a heater you can get that number down to around 6 hours.

If you plan on sanding the fiberglass I suggest using hefty gloves, a hospital style facemask, and safety glasses that cover your eyes well. Even with this protection you will still get fiberglass splinters. The best way to minimise the exposure is to make sure you do a good job with the application of the resin and making sure that your fiberglass cloth is cut perfectly to size. I suggest just using sandpaper sheets. For a perfectly smooth finish I recommend using a 120 grit followed by a 600 grit followed by a high grit. Be prepared to use a lot of the high grit sandpaper, fiberglass has a way with clogging the grits up.

To apply the fiberglass:

  1. Measure the area over which you want to fiber glass. Add approximately 2 inches (4 cm) overhang on each side because when you cut the cloth you will effectively loose when you cut the section out
  2. Place a piece of the cloth on the rocket to make sure that it is the right size
  3. Mix the resin with the hardener in the glass cup
  4. Apply generous amounts of resin to the cloth
  5. Use the squeegee to eliminate all air pockets and excess resin
  6. You can use a rag to wipe off the pools of resin as long as the resin is not close to curing
  7. Repeat the process for each piece

Here’s some pictures of my finished product.

Posted in Rockets | Leave a comment

Getting the Parts For My New RepRap Prusa

Here’s a list of all the parts for my Prusa Mendel RepRap where I bought them and their costs.

  1. $95Stepper Motors x 5
    http://www.alltronics.com/
    I got the Nema 17 2A bipolar 4 wire connection stepper motor. Any bipolar 4, 6, 8 wire connection will work as long as the holding torque is greater than 3 kg*cm. If you’re unsure about what to get for yourself just go to ultimachine.com and get the ones there. You need 5 steppers because one axis uses two steppers and one stepper is needed to drive the PLA plastic feed.
  2. $0Printed Plastic Parts
    ebay
    I actually got these parts from a friend, but you can order them from ebay. Search for “prusa” and get an SAE kit if you go with the same hardware store parts I did. THey should cost somewhere around $40 for just the plastic printed parts.
  3. $96 x Bearings 608ZZ 8x22x7
    http://www.amazon.com/
    Get 6 608 bearings for your RepRap. Buying a few extra is a good idea.
  4. $0Fans
    Luckily I had a friend with a few 40 mm fans that I could have. You’ll need 3 or 4 of them. They are available from alltronics or ultimachine.
  5. $30Power Supply
    ebay
    I got a 20 A 12 V power supply. Any power supply will work that has 12 V and at least 5 A or 15 A if you are going to run a hotpad.
  6. $66PLA Plastic
  7. $60Hardware Store Odds and Ends
    http://www.mcmaster.com/
    A couple metal rods and belts that can’t be printed.
  8. $200RAMP Complete Set Preassembled
    http://ultimachine.com/content/ramps-pre-assembled-kit-complete
    The RAMPS set is the guts of the Prusa, including the Arduino Mega microcontroller and the Pololu Stepper Motor Drivers
  9. $86Hot End Extruder Kit
    http://ultimachine.com/content/makergear-hot-end-kit-3mm-filament
    I got the the 36 mm length .35 mm diameter with the wooden mounting pieces.
Posted in 3D Printers | 1 Comment

Linux Starace Dark Theme Completed

Here’s a video of my finished Linux Starace Theme. If you have any comments about the setup or anything else linux leave a comment below.

Posted in ASUS G53SW Setup, Everything Penguin Related | 2 Comments

AE499

I’m in a quadrotor independent study class which will culminate into my first professional publication. More delineation later!

Posted in Quadrotors | Leave a comment

Change Login Sound Linux Mint, Ubuntu, Fedora – GNOME

If you ever feel like changing your login sound it’s a piece of cake. Go to Preferences -> Startup Applications. Look for an application called “GNOME Login Sound” and click edit. Delete the previous command and use vlc running in daemon mode (-d) to play the file of your choosing.

vlc /path/to/file.ext -d

This will work will almost any type of sound file (ogg, mp3, wav, et cetera.)

Posted in Everything Penguin Related, Uncategorized | Leave a comment

How to Import a Large CSV file to MySQL

I recently had to import a large csv file into mysql. Here’s how I did it. Also be sure that you have an ssh account/access to the terminal on the computer with the sql server.

1. Create the table you will store the items in.

Take a look at the top few lines of your csv file (using the head command makes this really easy). You might see something like this

Some Large Database
ID,Name, Phone, Address
1,James,505-234-2123,3456 Super St.
2,Mark,254-342-6732,7351 Roger Rd.
...

Notice that the csv file is set up with four columns.The first step is to create a table in a mysql database that has the three columns as fields in the table. I’m not going to show the specifics, but if you don’t know how to create a table in mysql google it. Remember if your database is big, be sure to put the index/primary/unique keys on before you upload the database.

2. Use the mysqlimport utility

Now comes the magic, here’s the command to upload your file.

mysqlimport  --ignore-lines=1 --fields-terminated-by=,
--columns='ID,Name,Phone,Address' --local -u root -p
Database /path/to/csvfile/TableName.csv 


Ignore-lines skips the first line “Some Large Database.” The –fields-terminated by tell the utility that the commas separate the columns. The –columns is used to map the order of the data in the csv file to the SQL database table. –local is very important. I’m not sure why it’s there but importing a csv file won’t work without it. The Database is the name of the database in which your table is stored. You must put the absolute path of the csv file for it to register with the utility. The “TableName.csv” has to match the name of the table in your mysql database.

For more information on the mysqlimport utility take a look at it’s reference page.
http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html

Hopefully this makes someone’s life easier. Leave a comment below if it does.

Posted in Everything Penguin Related | 5 Comments

Step By Step How to get Hibernate Working for Linux (Ubuntu 11.04, Mint 11)

What Hibernation Is and Does

Hibernation takes all the data in your ram and stores it on your hard drive and then powers down the computer. The data is stored in a special type of partition called a swap partition (you can also have a swap file). When you power the computer on again the data stored from your old session is reloaded.

In the following article I am going to lead you through a systematic approach to diagnosing why Linux’s hibernation feature isn’t working on your computer and hopefully fix it. Here’s a Brief overview.

1. Not Enough Swap
2. Your Computer Isn’t Saving Your Session
3. You Computer Isn’t Reading your Saved Session on Boot
4. Your Computer Says “resuming from /dev/sdX” but freezes

1. Not Enough Swap

You should have as much swap as you have RAM plus some margin. If you try to hibernate and you are using more ram than you have swap the process will fail and sometimes hangs. Sometimes there is an error message that says “not enough swap” This is an easy problem to check for. Run the command in red.

chris@Starace ~ $ free -m
             total       used       free     shared    buffers     cached
Mem:         10005       9922         82          0       1647       5844
-/+ buffers/cache:       2430       7574
Swap:         8100          0       8100

The output shows the amount of swap and ram on my computer. As you can see I have 8005 Mb of RAM and I have 8100 Mb of swap. For a hibernate to work you have to have more swap than used RAM not counting cached), Also if you run out of RAM during your session your swap is used. To hibernate you must have free swap greater than the sum of your RAM and your used swap. As a general rule you should have a swap partition slightly bigger than your RAM (hopefully you aren’t using swap during your session, if you are it’s time for a RAM upgrade.)

If you don’t have enough swap or if you don’t have any swap, roll up your sleeves you need to repartition your hard drive.

Repartitioning to add more SWAP

Remember to be careful with your repartitioning, you can destroy your OS easily.

  1. Pull out your bootable CD/Jump Drive and boot It (we can’t repartition the drive we we are using it.)
  2. Run the “gparted” disk utility.
  3. If you have swap, right click -> Delete
  4. Right click on your linux partition -> Resize/Move
  5. Decrease the size of the partition by the amount of space you want to increase your swap. Click Okay
  6. Right click on the free space -> New
  7. Change the File System Type to “linux-swap,” click okay.
  8. Click the apply check mark in the top menu of gparted to apply the changes
  9. Right Click On the new swap partition -> Information
  10. Copy down the UUID value and /dev/sdXN value for later.
Linux Create Parition

Make Sure the File System is linux-swap

uuid info linux

Copy down the UUID and path values. We will use them later.

Note:Remember to be careful with your repartitioning, you can destroy your OS easily. After repartitioning you will need to edit your Linux Hard Drive file. Open up terminal and run the command.

chris@Starace ~ $ sudo gedit /media/NAME_OF_YOUR_COMPUTER/etc/fstab

If you had a swap partition before, look for the line that has the word swap and change the /dev/sdXN to the new /dev/sdXN value. You can also use the UUID instead of the path as shown in red. If never had a swap partition to begin with add the following line to the bottom of the “/media/NAME_OF_YOUR_COMPUTER/etc/fstab” file.


UUID=a453-Your-UUID-Number-ea33 none swap sw

The path variable can change depending on how you have your hard drive plugged in (ex /dev/sda1 -> /dev/sdb1). This usually isn’t a problem if you don’t move your hard drives around in your computer. However, Using a UUID is more reliable. The /dev/sdXN designator can change, but the UUID is unique to the storage device and doesn’t change even if you move to another computer.

After you’ve made the changes to the fstab file, shut down and boot your computer normally. To make sure this all worked run the following command in red. You should see your swap partition listed.

chris@Starace ~ $ cat /proc/swaps
Filename				Type		Size	Used	Priority
/dev/sdNX                         partition	8295420	0	-1

If you see this take you have successfully created/expanded your swap to accommodate hibernation.

2. Your Computer Isn’t Saving Your Session

If you’ve tried to get your computer to hibernate and it didn’t work it’s helpful to look at the hibernation log.

tail /var/log/pm-suspend.log

chris@Starace ~ $ tail  /var/log/pm-suspend.log
Running hook /usr/lib/pm-utils/sleep.d/00powersave thaw hibernate:

/usr/lib/pm-utils/sleep.d/00powersave thaw hibernate: success.
Running hook /usr/lib/pm-utils/sleep.d/00logging thaw hibernate:

/usr/lib/pm-utils/sleep.d/00logging thaw hibernate: success.
Running hook /usr/lib/pm-utils/sleep.d/000kernel-change thaw hibernate:

/usr/lib/pm-utils/sleep.d/000kernel-change thaw hibernate: success.
Sun Jul 24 13:15:14 HST 2011: Finished.

If you see something that has a date and says “Finished” like the what is shown in blue, that means that your computer successfully saved the session. If you see a bunch of errors then get ready to roll up your sleeves again. Unfortunately this is the hardest error to fix. There could be dozens of reasons for this to happen, but in my case it had something to do with binding and unbinding peripheral devices. The following article explains what I did to fix the problem.

http://chriseiffel.com/everything-linux/how-i-got-suspend-and-hibernate-working-in-linux-ubuntu-11-04-mint-11/

One solution that I found that worked for a lot of people, but not me is this simple fix

http://www.ubuntugeek.com/fix-for-suspend-and-hibernation-problem-for-laptops.html/comment-page-2#comment-53547

Don’t lose hope if you get stuck in this step. Instead google everything you can on the problem. Google the errors you see in the log. Someone has solved the problem you just need to find the solution.

3. You Computer Isn’t Reading your Saved Session on Boot

So your computer successfully saves a session, but doesn’t resume the session upon power up? It acts as if it was rebooted rather than hibernated? Well the good news is that this is a fairly easy thing to fix. This is most likely because GRUB the bootloader doesn’t know to resume from your swap. Take a look at the GRUB profile.

chis@Starace ~ $ sudo gedit /etc/default/grub

Look for the line that starts with.

GRUB_CMDLINE_LINUX

Add the following option in red.

GRUB_CMDLINE_LINUX=”resume=UUID=a353e-Your-SWAP-UUID-34eda other-option=value”

Or

GRUB_CMDLINE_LINUX=”resume=/dev/sdXN other-option=value”

You may or may nor have other options. Be careful that you type in the correct path or UUID for the drive here. If you don’t then when you try to resume you will have to boot in safe mode to fix the drive name and re-run the update-grub script. Save the file and then update grub with the following command.

chris@Starace ~ $ sudo update-grub

In addition to grub we need to update/create one more file. Edit the following file.

chris@Starace ~ $ sudo gedit /etc/initramfs-tools/conf.d/resume 

Add this line to the file.

resume=UUID=41e86209-3802-424b-9a9d-d7683142dab7 

Then run this command to update.

chris@Starace ~ $ sudo update-initramfs -u

Now hibernate your computer and cross your fingers! It just might work.

4. Your Computer Says “resuming from /dev/sdX” but freezes

Linux is so close to hibernating and resuming successfully that it even says it is resuming. Fortunately this is another easy fix. The problem with this comes from two programs that are redundant. Removing them should fix the problem.

chris@Starace: sudo apt-get remove hibernate uswsusp

I know that the command may seem counterintuitive. but it worked for me so hopefully it will work for you.

All Done

Remember to check to make sure your USB ports work after the suspend/hibernate.

If you tried the steps above, please leave a comment below with your system setup (OS, Computer Hardware) so that we can create a reference that others can use.

Also I got a lot of my resources from the Ubuntu page on swap partitions. If you want to learn more about this subject read this article

https://help.ubuntu.com/community/SwapFaq

Happy Linuxing!

Posted in ASUS G53SW Setup, Everything Penguin Related | 36 Comments

How I got Suspend and Hibernate working in Linux (Ubuntu 11.04, Mint 11)

Suspend and hibernate have always been screwed up with Linux. Luckily if you absolutely need this feature there is hope. I got mine working after scouring google. In this tutorial I will share with you what I learned, and how I solved the “linux insomniac” problem for my laptop.

First, here’s what I’m running.
Linux Mint 11 (a derivative of Ubuntu 11.04)
Kernel Version 2.6.39.3
Asus G53SW (Very similar to any ASUS G73/G Series)

If you are running something different than I am above, don’t panic this still have a good chance of working for you. Regardless of what you do I encourage you to test your suspend and hibernate after everything you try. I know, you’ll have to hold the power button down a lot for a cold reset, but it’s worth it.

My Symptoms Before I got it Working

When I sent my computer in Hibernate the computer would look like it was doing what I told it to up until the part where the screen and the CPU fan turn off. I just got a screen of black that would not respond. The hibernate was very similar except there was a white cursor frozen at the top left of the screen. The only option I had was to hold the power button until it turned off.

An Easy Fix for Suspend

I scoured the web looking for something that might help me. I ran into an article which gives instructions on installing a script that may fix the problem. There are dozens of people who have left comment in the article as to whether it worked for them or not and what system they were running. Most of them left comments said that the script worked perfectly well for them.

The Fix
1. Create a new script. The scripts in the sleep.d directory get executed when your computer suspends and hibernates. The “20″ has something to do with the script load order and the name currently _custom-echi_hcd can be changed to anything you like

sudo gedit /etc/pm/sleep.d/20_custom-ehci_hcd 


2. Enter the following script into gedit.

#!/bin/sh
#inspired by http://art.ubuntuforums.org/showpost.php?p=9744970&postcount=19
#...and http://thecodecentral.com/2011/01/18/fix-ubuntu-10-10-suspendhibernate-not-working-bug    
# tidied by tqzzaa :)
# Comments added by chriseiffel.com

VERSION=1.1.1
DEV_LIST=/tmp/usb-dev-list
DRIVERS_DIR=/sys/bus/pci/drivers
DRIVERS="ehci xhci" # ehci_hcd, xhci_hcd
HEX="[[:xdigit:]]"
MAX_BIND_ATTEMPTS=2
BIND_WAIT=0.1

#This function executes when the computer is going
#into sleep/hibernation. It looks for all devices
#in /sys/bus/pci/drivers with the ehci_hcd, etc
#and adds them to the unbind list
unbindDev() {
  echo -n > $DEV_LIST 2>/dev/null
  for driver in $DRIVERS; do
    DDIR=$DRIVERS_DIR/${driver}_hcd
    for dev in `ls $DDIR 2>/dev/null | egrep "^$HEX+:$HEX+:$HEX"`; do
      echo -n "$dev" > $DDIR/unbind
      echo "$driver $dev" >> $DEV_LIST
    done
  done
}

#Executed on a resume/thaw attempts to rebind the stored drivers
bindDev() {
  if [ -s $DEV_LIST ]; then
    while read driver dev; do
      DDIR=$DRIVERS_DIR/${driver}_hcd
      while [ $((MAX_BIND_ATTEMPTS)) -gt 0 ]; do
          echo -n "$dev" > $DDIR/bind
          if [ ! -L "$DDIR/$dev" ]; then
            sleep $BIND_WAIT
          else
            break
          fi
          MAX_BIND_ATTEMPTS=$((MAX_BIND_ATTEMPTS-1))
      done  
    done < $DEV_LIST
  fi
  rm $DEV_LIST 2>/dev/null
}

case "$1" in
  hibernate|suspend) unbindDev;;
  resume|thaw)       bindDev;;
esac

3. You’re done. You shouldn’t need to restart your computer. Try a suspend. Cross your fingers. Remember to check to make sure that your USB devices are still working after a resume/thaw.

Unfortunately for me and some others it didn’t work perfectly. In my case it was bitter sweet, my suspend worked, but my hibernate still didn’t work. However, it did change the way that suspend didn’t work. Now instead of a black screen, the computer just acted as if it was a normal restart. On power up instead of continuing the session it just restarted. If you have this same problem continue on getting article on getting hibernation. working.

The website and the script I originally found are located here.
http://thecodecentral.com/2011/01/18/fix-ubuntu-10-10-suspendhibernate-not-working-bug/

Posted in ASUS G53SW Setup, Everything Penguin Related | 25 Comments