From: Jeremy on
I would like to import a complicated data set from excel into MatLab. What I'd like to achieve is a structure array where each field represents a column variable for example.

aa.TrialNumber
aa.MaleID
aa.FemaleID
aa.TimeInTrial
aa.FileNames

What I'd like to be able to do is access 1 trial worth of data by using a similar command as: aa(1,1) to get the following output

TrialNumber: 1
MaleID: 23.4
FemaleID: 22.1
TimeInTrial: [0 12 16 36]
FileNames: ['P0' 'P12' 'P16' 'P36']

I know one problem I could encounter is that not all of my fields have the same number of rows due to trial level variation. I'm relatively new to MatLab, so if you have suggestions please take that into consideration - Thanks you. Please let me know if you need other information to assist with this question.
From: TideMan on
On Apr 27, 1:12 pm, "Jeremy " <jsg...(a)mail.missouri.edu> wrote:
> I would like to import a complicated data set from excel into MatLab.  What I'd like to achieve is a structure array where each field represents a column variable for example.
>
> aa.TrialNumber
> aa.MaleID
> aa.FemaleID
> aa.TimeInTrial
> aa.FileNames
>
> What I'd like to be able to do is access 1 trial worth of data by using a similar command as: aa(1,1) to get the following output
>
> TrialNumber: 1
> MaleID: 23.4
> FemaleID: 22.1
> TimeInTrial: [0 12 16 36]
> FileNames: ['P0' 'P12' 'P16' 'P36']
>
> I know one problem I could encounter is that not all of my fields have the same number of rows due to trial level variation.  I'm relatively new to MatLab, so if you have suggestions please take that into consideration - Thanks you.  Please let me know if you need other information to assist with this question.

Looks good to me.
But don't sit thinking about.
Do it!!

e.g., for trial ino:
[a,b]=xlsread(xlsfile);
for icol=1:size(a,2)
aa(ino).(b{icol})=a(:,icol);
end

From: us on
"Jeremy " <jsgth5(a)mail.missouri.edu> wrote in message <hr5dl5$fgp$1(a)fred.mathworks.com>...
> I would like to import a complicated data set from excel into MatLab. What I'd like to achieve is a structure array where each field represents a column variable for example.
>
> aa.TrialNumber
> aa.MaleID
> aa.FemaleID
> aa.TimeInTrial
> aa.FileNames
>
> What I'd like to be able to do is access 1 trial worth of data by using a similar command as: aa(1,1) to get the following output
>
> TrialNumber: 1
> MaleID: 23.4
> FemaleID: 22.1
> TimeInTrial: [0 12 16 36]
> FileNames: ['P0' 'P12' 'P16' 'P36']
>
> I know one problem I could encounter is that not all of my fields have the same number of rows due to trial level variation. I'm relatively new to MatLab, so if you have suggestions please take that into consideration - Thanks you. Please let me know if you need other information to assist with this question.

a hint:
- also, look at

help cell2struct;
help struct;

us
From: Ashish Uthama on
On Mon, 26 Apr 2010 22:12:05 -0300, Jeremy <jsgth5(a)mail.missouri.edu>
wrote:

> I would like to import a complicated data set from excel into MatLab.
> What I'd like to achieve is a structure array where each field
> represents a column variable for example.
>
> aa.TrialNumber
> aa.MaleID
> aa.FemaleID
> aa.TimeInTrial
> aa.FileNames
>
> What I'd like to be able to do is access 1 trial worth of data by using
> a similar command as: aa(1,1) to get the following output
>
> TrialNumber: 1
> MaleID: 23.4
> FemaleID: 22.1
> TimeInTrial: [0 12 16 36]
> FileNames: ['P0' 'P12' 'P16' 'P36']
>
> I know one problem I could encounter is that not all of my fields have
> the same number of rows due to trial level variation. I'm relatively
> new to MatLab, so if you have suggestions please take that into
> consideration - Thanks you. Please let me know if you need other
> information to assist with this question.

Code in this example might be useful:
http://www.mathworks.com/matlabcentral/fileexchange/19707-xls2var
From: Jeremy on
"Ashish Uthama" <first.last(a)mathworks.com> wrote in message <op.vbtpfme5a5ziv5(a)uthamaa.dhcp.mathworks.com>...
> On Mon, 26 Apr 2010 22:12:05 -0300, Jeremy <jsgth5(a)mail.missouri.edu>
> wrote:
>
> > I would like to import a complicated data set from excel into MatLab.
> > What I'd like to achieve is a structure array where each field
> > represents a column variable for example.
> >
> > aa.TrialNumber
> > aa.MaleID
> > aa.FemaleID
> > aa.TimeInTrial
> > aa.FileNames
> >
> > What I'd like to be able to do is access 1 trial worth of data by using
> > a similar command as: aa(1,1) to get the following output
> >
> > TrialNumber: 1
> > MaleID: 23.4
> > FemaleID: 22.1
> > TimeInTrial: [0 12 16 36]
> > FileNames: ['P0' 'P12' 'P16' 'P36']
> >
> > I know one problem I could encounter is that not all of my fields have
> > the same number of rows due to trial level variation. I'm relatively
> > new to MatLab, so if you have suggestions please take that into
> > consideration - Thanks you. Please let me know if you need other
> > information to assist with this question.
>
> Code in this example might be useful:
> http://www.mathworks.com/matlabcentral/fileexchange/19707-xls2var

Thanks everyone for giving advise - much appreciated. Tideman, I came up with a similar solution as the one you proposed, I just couldn't figure out how to combine the created arrays into a structure array.

Ashish - thanks for suggesting the above post! It is very close to what I'd like to accomplish more automatically. Currently we create the same type of structure by copying each excel column into Matlab (which is a serious pain for large datasets). So the issue now, is how can I turn the 1x1 structure into a 1xN structure where each N is (from my above example) all of the fields for trial 1? - Thanks