# MATLAB excel import troubles

• Feb 4th 2009, 03:56 AM
fluxx2
MATLAB excel import troubles
Lately, I have been playing around with the Excel spreadsheet import functions. What I am trying to do is to import both text and numerical values, and then have each text column correspond to each numerical column. For instance:

Let us assume that we have a excel speadsheet:

first column second column
Text A 10
Text B 20
Text C 30

While [text, data] = xlsread('name of spreadsheet') pulls both the text and the numerical value from the excel spreadsheet, it does so assigning "name = A B C" and "data = 10 20 30" Is there a way to automatically assign "A = 10, B = 20, C = 30"?

I apologize if this has been asked before. I have searched far and wide, without finding the answer. The Matlab help file also comes up empty on this.
• Feb 4th 2009, 04:39 AM
Constatine11
Quote:

Originally Posted by fluxx2
Lately, I have been playing around with the Excel spreadsheet import functions. What I am trying to do is to import both text and numerical values, and then have each text column correspond to each numerical column. For instance:

Let us assume that we have a excel speadsheet:

first column second column
Text A 10
Text B 20
Text C 30

While [text, data] = xlsread('name of spreadsheet') pulls both the text and the numerical value from the excel spreadsheet, it does so assigning "name = A B C" and "data = 10 20 30" Is there a way to automatically assign "A = 10, B = 20, C = 30"?

I apologize if this has been asked before. I have searched far and wide, without finding the answer. The Matlab help file also comes up empty on this.

I don't think you want to do this as you would not know what the variable names were going to be so could not use them subsequently. If you know that they will be A, B and C in some order then to determin that order and assign them to variables of that name you will have to parse the string array that holds them to determine the actual order.

.
• Feb 4th 2009, 06:48 AM
fluxx2
Well the idea is that the text corresponds to the numeric value to the right of it in the actual Excel file.

Imagine, for instance, an Excel balance sheet with the account "Cash" in the left column and the amount of cash in the right column. Once the Excel spreadsheet is loaded into MATLAB, the end user would just be able to type Cash and have the value of cash returned to him or her.
• Feb 4th 2009, 08:18 AM
fluxx2

Let us assume that i load the variables into MATLAB. I now have "name = A B C" and "data = 10 20 30". Is there a way to have MATLAB show these variables next to each other, like a matrix, although they do not necessarily have to be linked. You can do it with numbers, of course, but what about numbers and text.

Illustration of what I would like MATLAB to show:

A 10
B 20
C 30
• Feb 4th 2009, 02:19 PM
Constatine11
Quote:

Originally Posted by fluxx2

Let us assume that i load the variables into MATLAB. I now have "name = A B C" and "data = 10 20 30". Is there a way to have MATLAB show these variables next to each other, like a matrix, although they do not necessarily have to be linked. You can do it with numbers, of course, but what about numbers and text.

Illustration of what I would like MATLAB to show:

A 10
B 20
C 30

I don't use them myself, but I think a cell array might be what you want (you will have to look this up in the documentation)

.
• Feb 5th 2009, 12:08 AM
fluxx2
Thank you I will look into it. Cheers!
• Feb 5th 2009, 07:44 AM
fluxx2
I have manage to make a cell array of both lists of data.

"listData = {text(1,1:end) data}"

The question is then how one could pull the the stringts vertically and have the first cell text correspond to the second cell data. In other words, text = data.