Monday Math Madness #30 Winner: Placing Bath Tiles

MMM #30 Winner

mmmwin.jpg

The winner for this edition of MMM is Ingmar Dasseville. Everyone was able to show that there is no way to place the bath tiles I have. Perhaps the problem was too easy and too similar to a classic chess problem. Thanks for everyone who submitted! One of the good explanation is provided below by Gareth McCaughan.

If you did not find this round of MMM to be challenging, next week is Sol’s turn over at wildaboutmath.com. Be prepared!

The Answer by Gareth McCaughan

bathtiles.png

The number of ways to place the tiles is 0.

Colour the squares of the board in checkerboard fashion. If two corners weren’t missing, there would be equal numbers of black and white squares. The two missing corners were the same colour, so there are two more (say) black squares than (say) white ones. But each 2×1 tile, however you place it, covers one white and one black square, so there is no way to use them to cover a set of squares with unequal numbers of black and white squares.

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

MATLAB - Using XLSREAD to Import Excel Data

Matlab Logo Microsoft Excel is a common data format, so it’s a good idea to learn how to work with it in the MATLAB environment. There are a couple of ways to import Excel data, and we’ll discuss how to use the XLSREAD command to do it.

Contents

XLSREAD - When Data is Numerical

When the Excel data consists entirely of numbers, importing the data to MATLAB is straightforward. For example, take the Excel file, test.xls, shown below:

xlsread image 01

We can import the data into MATLAB using the following command:

%import the excel data into MATLAB
[numericalData] = xlsread('test.xls');
numericalData =

    1.0000   50.0000   66.1000
    2.0000  100.0000   32.4000
    3.0000  150.0000   70.5000
    4.0000  200.0000   33.8000
    5.0000  250.0000   14.0000
    6.0000  300.0000  187.7000
    7.0000  350.0000  105.4000
    8.0000  400.0000   88.1000
    9.0000  450.0000  102.6000
   10.0000  500.0000   64.6000

XLSREAD - When Data Contains Header Lines, Column Headers, and Numbers

Most of the time, you will probably be dealing with Excel data that contains header lines and column headers, as shown below. In this instance, it’s going to take a little more work to get the data that you want.

xlsread image 02

%import the excel data into MATLAB
[numericalData, textData] = xlsread('test.xls');
numericalData =

    1.0000   50.0000   66.1000
    2.0000  100.0000   32.4000
    3.0000  150.0000   70.5000
    4.0000  200.0000   33.8000
    5.0000  250.0000   14.0000
    6.0000  300.0000  187.7000
    7.0000  350.0000  105.4000
    8.0000  400.0000   88.1000
    9.0000  450.0000  102.6000
   10.0000  500.0000   64.6000

textData = 

    [1x46 char]       ''         ''
    [1x49 char]       ''         ''
             ''       ''         ''
    'Sample'       'Gen'    'Power'
%use the following code to verify the contents of the cell array
textData{1:2,1}

Sure enough, it matches!

ans =

This data set was created on April 10th, 2009.

ans =

Blinkdagger.com owns all rights to this data set.

XLSREAD - When Data Contains Both Numbers and Strings

What happens when your data consists of both numbers and strings, as shown in the example below? When you have a mixture of data types, the best way to import the Excel data is in the raw data format. In this format, the data is stored into a cell array.

xlsread image 03

%xlsread allows you to store the raw data into a cell array
[numericalData, textData, rawData] = xlsread('test.xls');
rawData = 

    [1x46 char]    [NaN]    [     NaN]    [   NaN]
    [1x49 char]    [NaN]    [     NaN]    [   NaN]
    [      NaN]    [NaN]    [     NaN]    [   NaN]
    'Sample'       'Gen'    'Power'       'Color'
    [        1]    [ 50]    [ 66.1000]    'Green'
    [        2]    [100]    [ 32.4000]    'Red'
    [        3]    [150]    [ 70.5000]    'Blue'
    [        4]    [200]    [ 33.8000]    'Green'
    [        5]    [250]    [      14]    'Green'
    [        6]    [300]    [187.7000]    'Blue'
    [        7]    [350]    [105.4000]    'Red'
    [        8]    [400]    [ 88.1000]    'Red'
    [        9]    [450]    [102.6000]    'Black'
    [       10]    [500]    [ 64.6000]    'Yellow'

At this point, it will take a lot of cell array manipulation to get the data into the format that you want. ass=”comment”>%xlsread allows you to store the raw data into a cell array
[numericalData, textData, rawData] = xlsread(‘test.xls’);

rawData = 

    [1x46 char]    [NaN]    [     NaN]    [   NaN]
    [1x49 char]    [NaN]    [     NaN]    [   NaN]
    [      NaN]    [NaN]    [     NaN]    [   NaN]
    'Sample'       'Gen'    'Power'       'Color'
    [        1]    [ 50]    [ 66.1000]    'Green'
    [        2]    [100]    [ 32.4000]    'Red'
    [        3]    [150]    [ 70.5000]    'Blue'
    [        4]    [200]    [ 33.8000]    'Green'
    [        5]    [250]    [      14]    'Green'
    [        6]    [300]    [187.7000]    'Blue'
    [        7]    [350]    [105.4000]    'Red'
    [        8]    [400]    [ 88.1000]    'Red'
    [        9]    [450]    [102.6000]    'Black'
    [       10]    [500]    [ 64.6000]    'Yellow'

At this point, it will take a lot of cell array manipulation to get the data into the format that you want. Read on for some more tips on importing data!

Other Options for XLSREAD

  • Specify WorkSheet - Let’s say you have the following Excel file. Notice that the data is on Sheet 2 now.

    xlsread image 04

    By default, XLSREAD reads the first sheet within the Excel File. You can specify which sheet you want to read the data from by doing the following:

    %specify which sheet you want to import data from
    [numericalData] = xlsread('test.xls','Sheet2');
    
  • Specify Range - Let’s say you have the following Excel file, and you only want to extract the information in the red rectangle.

    xlsread image 05

    You can do this by using the following code:

    %specify the sheet and the range you want to import
    [numericalData] = xlsread('test.xls','Sheet2','A9:C14');
    
  • Cut and paste directly into MATLAB: This one doesn’t have anything to do with XLSREAD. It’s a technique that I use sometimes when I need to import data quickly. First, I create an empty variable, and then open up the array editor.
    %create an empty variable
    data = [];
    %opens up the data variable in the Variable Editor
    openvar data;
    

    Alternatively, you can open up the Variable Editor by double clicking on the data variable from within the main workspace.

    xlsread image 06 Finally, paste the data into the empty array.

Next Time: XLSWRITE

Next time, we will discuss the intricacies of XLSWRITE.

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

MATLAB GUI - Tool Tips are your Friends!

Matlab Logo Tool Tips are something that is often overlooked in building a GUI. These handy descriptions can come in quite handy in almost all situations as they provide extra information.

Contents

What is a Tool Tip?

A tool tip is supplementary information about a GUI component that appears when the user hovers the mouse cursor over the GUI component. As you can imagine, this can be quite useful for the user. See below for examples.

  • Tool Tip for the add button:
    Tool Tip 01
  • Tool tip for the first input parameter:
    Tool Tip 02
  • Tool tip for the second input parameter:
    Tool Tip 03

How to Add Tool Tips

Within the GUIDE editor, you can add a tool tip by modifying the “TooltipString” property using the Property Inspector. Simply double click on the component to bring up the Property Inspector. The image below shows that the “TooltipString” property has been modified for the Add! button.

Tool Tip Property

Adding Tool Tips Programmatically

If you would rather add the tool tips within your code, you can use the SET command. For instance, if you wanted to add a tool tip for the add button, you could do the following in the opening function of the GUI:

%put this code into the opening function of the GUI
 
set(handles.input1_editText,'TooltipString','This is the first input.')
set(handles.input2_editText,'TooltipString','This is the second input.')
set(handles.add_pushbutton,'TooltipString','This is a tool tip! Press to add.')

If you have a large list of tooltips, you may want to do it in separate m-file and call that m-file in the opening function.

Download the Source Files and Other Links

Download the source files here.
Yair’s Undocumented Tips on How to Spice up Tooltips

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

Monday Math Madness #30: Placing Bath Tiles

mmm

bathtiles.png

Continue Reading »

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

Rob Slazas Enjoys Sushi

The Man with The Stat Plan: Rob Slazas!

Last week, Rob Slazas just happened to be in the Los Angeles area so he and I met up and had some scrumptious sushi. For more than a year now, he’s been providing us with great ideas and support when it comes to the website. He has authored some pretty cool posts that mainly focus on statistics, but he also has well known love-affair with the TEXTSCAN function. He has been a great help getting this MATLAB blog to where it is today, so when he told me that he would be in town for a day or two, I jumped on the chance to meet up with my fellow blogger.

Here we are at the local sushi restaurant, about to feast on the food.

quan_rob.jpg

Two Engineers is One Too Many

So what happens when two engineers get together? Well, the inner geek takes over and the discussions inevitably turn towards topics of statistics, numbers, mathematics, MATLAB, and other nerd related things. We actually spent some time discussing a problem that we will be presenting in the immediate future, so stay tuned for that. And for the sake of not boring the readers, I will omit the rest of the details on our conversation.

Lunch, Anyone?

If any of our readers are in the Los Angeles or Boston area and would be interested in meeting the folks behind blinkdagger, leave a comment and maybe we can meet up for lunch/dinner and some intellectual and stimulating MATLAB conversation!

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

« Prev - Next »