From: Meike on
Hey!

I'm a frustrated MATLAB beginner and need some help.

I have a structure array containing two double arrays and one cell array:

S =
[127x1 double] [127x1 double] {127x1 cell}

The cell array contains the information (strings) that I'd like to classify/find. The two double arrays contain the related information I'd like to receive (scalars).

For example I tried to use arrayfun(@(x)find(x.h==4),f,'uniformoutput',false), but I just get an error message.
I also used this function idx_X = find(ismember(names, 'X')==1), but it just works for one array.

I'd like MATLAB to compute all the "X", "Y" and "Z" elements of the cell array separately and receive the to X, Y and Z related rows of the two double arrays.

I hope anybody knows how I could do it.

Thanks,
Meike
From: Oleg Komarov on
"Meike " <meikeimregenwald(a)gmx.net> wrote in message <i0doh8$lud$1(a)fred.mathworks.com>...
> Hey!
>
> I'm a frustrated MATLAB beginner and need some help.
>
> I have a structure array containing two double arrays and one cell array:
>
> S =
> [127x1 double] [127x1 double] {127x1 cell}
>
> The cell array contains the information (strings) that I'd like to classify/find. The two double arrays contain the related information I'd like to receive (scalars).
>
> For example I tried to use arrayfun(@(x)find(x.h==4),f,'uniformoutput',false), but I just get an error message.
> I also used this function idx_X = find(ismember(names, 'X')==1), but it just works for one array.
>
> I'd like MATLAB to compute all the "X", "Y" and "Z" elements of the cell array separately and receive the to X, Y and Z related rows of the two double arrays.
>
> I hope anybody knows how I could do it.
>
> Thanks,
> Meike

From the output it seems you have cell array and not a structure:
S = {rand(127,1),rand(127,1),cellstr(char(rand(127,1)*30+80))}
S =
[127x1 double] [127x1 double] {127x1 cell}

lets say you need to find the letter 'T' in the cell array of strings S{1,3}:
IDX = strcmp('T',S{1,3});
Then retrieve the value from the double in cell S{1,2} by using the indexed position:
S{1,2}(IDX)

You may find useful to read the getting started guide on how cell arrays work but in general if you have S, a "m by n" cell array, with S{row,col} you get inside the content of that cell while with S(row,col) you retrieve the content wrapped inside the cell.

Hope I wasn't to boring

Oleg
From: us on
"Meike " <meikeimregenwald(a)gmx.net> wrote in message <i0doh8$lud$1(a)fred.mathworks.com>...
> Hey!
>
> I'm a frustrated MATLAB beginner and need some help.
>
> I have a structure array containing two double arrays and one cell array:
>
> S =
> [127x1 double] [127x1 double] {127x1 cell}
>
> The cell array contains the information (strings) that I'd like to classify/find. The two double arrays contain the related information I'd like to receive (scalars).
>
> For example I tried to use arrayfun(@(x)find(x.h==4),f,'uniformoutput',false), but I just get an error message.
> I also used this function idx_X = find(ismember(names, 'X')==1), but it just works for one array.
>
> I'd like MATLAB to compute all the "X", "Y" and "Z" elements of the cell array separately and receive the to X, Y and Z related rows of the two double arrays.
>
> I hope anybody knows how I could do it.
>
> Thanks,
> Meike

your example is completely confusing(!)...
- there's an S: apparently a CELL and NOT a STRUCT ARRAY as you say...
- there's an F: apparently a STRUCT with field .H...
- there's a NAMES: apparently a CELL of CHARs...
make up your mind and produce a consistent example...

us
From: Meike on
"Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <i0dpsa$iv7$1(a)fred.mathworks.com>...
> "Meike " <meikeimregenwald(a)gmx.net> wrote in message <i0doh8$lud$1(a)fred.mathworks.com>...
> > Hey!
> >
> > I'm a frustrated MATLAB beginner and need some help.
> >
> > I have a structure array containing two double arrays and one cell array:
> >
> > S =
> > [127x1 double] [127x1 double] {127x1 cell}
> >
> > The cell array contains the information (strings) that I'd like to classify/find. The two double arrays contain the related information I'd like to receive (scalars).
> >
> > For example I tried to use arrayfun(@(x)find(x.h==4),f,'uniformoutput',false), but I just get an error message.
> > I also used this function idx_X = find(ismember(names, 'X')==1), but it just works for one array.
> >
> > I'd like MATLAB to compute all the "X", "Y" and "Z" elements of the cell array separately and receive the to X, Y and Z related rows of the two double arrays.
> >
> > I hope anybody knows how I could do it.
> >
> > Thanks,
> > Meike
>
> From the output it seems you have cell array and not a structure:
> S = {rand(127,1),rand(127,1),cellstr(char(rand(127,1)*30+80))}
> S =
> [127x1 double] [127x1 double] {127x1 cell}
>
> lets say you need to find the letter 'T' in the cell array of strings S{1,3}:
> IDX = strcmp('T',S{1,3});
> Then retrieve the value from the double in cell S{1,2} by using the indexed position:
> S{1,2}(IDX)
>
> You may find useful to read the getting started guide on how cell arrays work but in general if you have S, a "m by n" cell array, with S{row,col} you get inside the content of that cell while with S(row,col) you retrieve the content wrapped inside the cell.
>
> Hope I wasn't to boring
>
> Oleg



Thanks, Oleg! That's exactly what I want to do and it works fine!

You are right it is not a structure array.
Sorry, I am a beginner and lots of things are confusing me.