# Thread: MATLAB excel import troubles

1. ## 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.

2. 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.

.

3. 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.

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

5. 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)

.

6. Thank you I will look into it. Cheers!

7. 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.