Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
text matrix xlsread

Subject: text matrix xlsread

From: Goliath davidson

Date: 29 Jul, 2009 17:45:07

Message: 1 of 3

Lets say I have a matrix of data like so in excel;

matrix1 =
1 31 5W 412
2 32 3N 432
3 45 2C 643
4 24 8V 123
5 14 9E 754
6 67 6G 757

What I want to do is read this matrix into matlab from excel. I then want to duplicate the rows with a program that I already have. Finally, I want to write the data back into matlab.

The matrix has text and numbers in it as shown.

Is there any way that I can maybee assign values to the
text data (for example 6G = 1111111111) that way I can manipulate the matrix with all numbers and no text data.

Then I would need to write the data back into excel and display it as text data again.

Ive been stuck on this task for a very long time
thanks,
G. Davidson

Subject: text matrix xlsread

From: Brittany

Date: 29 Jul, 2009 19:53:01

Message: 2 of 3

Goliath davidson <lbyrnesrealty@aol.com> wrote in message <24846551.16613.1248889537734.JavaMail.jakarta@nitrogen.mathforum.org>...
> Lets say I have a matrix of data like so in excel;
>
> matrix1 =
> 1 31 5W 412
> 2 32 3N 432
> 3 45 2C 643
> 4 24 8V 123
> 5 14 9E 754
> 6 67 6G 757
>
> What I want to do is read this matrix into matlab from excel. I then want to duplicate the rows with a program that I already have. Finally, I want to write the data back into matlab.
>
> The matrix has text and numbers in it as shown.
>
> Is there any way that I can maybee assign values to the
> text data (for example 6G = 1111111111) that way I can manipulate the matrix with all numbers and no text data.
>
> Then I would need to write the data back into excel and display it as text data again.
>
> Ive been stuck on this task for a very long time
> thanks,
> G. Davidson

From the documentation on xlsread (worth reading, as well as the one on xlswrite if you haven't already):

"Any inner rows or columns in which some or all cells contain nonnumeric data are not ignored. Instead, xlsread assigns a value of NaN to the nonnumeric cells"

So unless a more experienced member knows otherwise, those cells with letters will all be read in as NaN. So as far as workarounds, you'll have to assign those numbers you were talking about in excel before you convert them. Also, converting the letters to their ascii codes might be a useful way to keep track of them.

On the plus side, if you know what these strings of numbers that correspond to letters are, you can, before writing, place your matrix in a cell array, search for those strings of numbers and replace them with the proper letters, then write.

So long story short, I don't think you can read letters of any kind. But letters CAN be written.

Subject: text matrix xlsread

From: Dave Brackett

Date: 29 Jul, 2009 20:00:20

Message: 3 of 3

"Brittany " <baklein@umd.edu> wrote in message <h4q9at$hd4$1@fred.mathworks.com>...
> Goliath davidson <lbyrnesrealty@aol.com> wrote in message <24846551.16613.1248889537734.JavaMail.jakarta@nitrogen.mathforum.org>...
> > Lets say I have a matrix of data like so in excel;
> >
> > matrix1 =
> > 1 31 5W 412
> > 2 32 3N 432
> > 3 45 2C 643
> > 4 24 8V 123
> > 5 14 9E 754
> > 6 67 6G 757
> >
> > What I want to do is read this matrix into matlab from excel. I then want to duplicate the rows with a program that I already have. Finally, I want to write the data back into matlab.
> >
> > The matrix has text and numbers in it as shown.
> >
> > Is there any way that I can maybee assign values to the
> > text data (for example 6G = 1111111111) that way I can manipulate the matrix with all numbers and no text data.
> >
> > Then I would need to write the data back into excel and display it as text data again.
> >
> > Ive been stuck on this task for a very long time
> > thanks,
> > G. Davidson
>
> From the documentation on xlsread (worth reading, as well as the one on xlswrite if you haven't already):
>
> "Any inner rows or columns in which some or all cells contain nonnumeric data are not ignored. Instead, xlsread assigns a value of NaN to the nonnumeric cells"
>
> So unless a more experienced member knows otherwise, those cells with letters will all be read in as NaN. So as far as workarounds, you'll have to assign those numbers you were talking about in excel before you convert them. Also, converting the letters to their ascii codes might be a useful way to keep track of them.
>
> On the plus side, if you know what these strings of numbers that correspond to letters are, you can, before writing, place your matrix in a cell array, search for those strings of numbers and replace them with the proper letters, then write.
>
> So long story short, I don't think you can read letters of any kind. But letters CAN be written.

The documentation also states a bit further down the page:
[num, txt, raw] = xlsread(filename, ...) returns numeric and text data in num and txt, and unprocessed cell content in cell array raw, which contains both numeric and text data.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us