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:
xlsread importing cell array

Subject: xlsread importing cell array

From: Alaa Elwany

Date: 7 Jan, 2012 23:11:08

Message: 1 of 5

Hi,

I use
[num,txt,raw] = xlsread('Mysheet.xlsx')
to import some data from Excel, having both strings and numbers.

What I need to do next is store columns of "raw" as a separate cell arrays.

[num,txt,raw] = xlsread('Mysheet.xlsx')
A = raw(:,1);
B = raw(:,2);
C = raw(:,3:5);
D = raw(:,6);

Notice Cell array C above: I need this to have columns 3-5 of "raw".

Strange problem is:
When I write the command C = raw(:,3:5); in the Matlab command window, it works fine. I get a 3-column cell array, each column having length equal to length(raw).

However, when I have the whole code above in an M file, and run it, the array C is created as a ONE ROW vector having (3*length(raw)) elements in it!

It seems very strange that the command works correctly when I use it in the Command window, but THE SAME COMMAND works incorrectly when I use it in an M file.

Has anyone seen something like this before?

Thanks a lot in advance,

Alaa

Subject: xlsread importing cell array

From: Matt J

Date: 7 Jan, 2012 23:33:08

Message: 2 of 5

"Alaa Elwany" <alaa_elwany@yahoo.com> wrote in message <jeajec$m8q$1@newscl01ah.mathworks.com>...
>
> It seems very strange that the command works correctly when I use it in the Command window, but THE SAME COMMAND works incorrectly when I use it in an M file.
>
> Has anyone seen something like this before?
================

It does sound peculiar, but since you haven't given any sample code with which we can reproduce this, the only thing we can suppose is that somewhere downstream of the commands you've shown you have additional code that reshapes the data inadvertently.

Subject: xlsread importing cell array

From: Alaa Elwany

Date: 9 Jan, 2012 14:34:08

Message: 3 of 5

"Matt J" wrote in message <jeaknj$pn8$1@newscl01ah.mathworks.com>...
> "Alaa Elwany" <alaa_elwany@yahoo.com> wrote in message <jeajec$m8q$1@newscl01ah.mathworks.com>...
> >
> > It seems very strange that the command works correctly when I use it in the Command window, but THE SAME COMMAND works incorrectly when I use it in an M file.
> >
> > Has anyone seen something like this before?
> ================
>
> It does sound peculiar, but since you haven't given any sample code with which we can >reproduce this, the only thing we can suppose is that somewhere downstream of the >commands you've shown you have additional code that reshapes the data inadvertently.

Hi Matt,
My code is very simple:

[num,txt,raw] = xlsread('POCv1.xlsm');

raw(1,:) = []; % Here, I just need to delete the first row of array "raw"

a = raw(:,1);
b = raw(:,2);
c = raw(:,3);
d = raw(:,4:6);


Like I said, arrays (a,b,c) turn out just fine. However, Array "d" comes as a ONE ROW array having all the elements in columns (4:6) of raw!

When I go to the Command window of Matlab and enter:
d = raw(:,4:6);

The array "d" comes correctly as a three-column array with columns (4:6) of "raw".

Very odd!

Any input?

thank you very much for your help.

Subject: xlsread importing cell array

From: Matt J

Date: 9 Jan, 2012 15:12:08

Message: 4 of 5

"Alaa Elwany" <alaa_elwany@yahoo.com> wrote in message <jeett0$rj7$1@newscl01ah.mathworks.com>...
>
> Like I said, arrays (a,b,c) turn out just fine. However, Array "d" comes as a ONE ROW array having all the elements in columns (4:6) of raw!
>
> When I go to the Command window of Matlab and enter:
> d = raw(:,4:6);
>
> The array "d" comes correctly as a three-column array with columns (4:6) of "raw".
>
> Very odd!
>
> Any input?
==================


I can't reproduce it. For me raw(:,4:6) comes out just fine - a 3 column cell array as expected. I'm using my own self-made spreadsheet, though. You'll probably have to give instructions on how we should duplicate
'POCv1.xlsm'

Subject: xlsread importing cell array

From: Alaa Elwany

Date: 10 Jan, 2012 17:24:08

Message: 5 of 5

"Matt J" wrote in message <jef048$6f5$1@newscl01ah.mathworks.com>...
> "Alaa Elwany" <alaa_elwany@yahoo.com> wrote in message <jeett0$rj7$1@newscl01ah.mathworks.com>...
> >
> > Like I said, arrays (a,b,c) turn out just fine. However, Array "d" comes as a ONE ROW array having all the elements in columns (4:6) of raw!
> >
> > When I go to the Command window of Matlab and enter:
> > d = raw(:,4:6);
> >
> > The array "d" comes correctly as a three-column array with columns (4:6) of "raw".
> >
> > Very odd!
> >
> > Any input?
> ==================
>
>
> I can't reproduce it. For me raw(:,4:6) comes out just fine - a 3 column cell array as expected. I'm using my own self-made spreadsheet, though. You'll probably have to give instructions on how we should duplicate
> 'POCv1.xlsm'

Thanks a lot Matt. I appreciate your feedback. I will see if I can provide a simple instructions to reproduce 'POCv1.xlsm'. Have a great day.

Tags for 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