Asked by Bluegin
on 22 Aug 2019 at 14:30

Hi,

I have a multi-layered structure A that include 3 structures (a, b and c) and and all of them contain 10 fieldnames with 10 rows and every cell further contains 10 double numbers mixed with nans.

Doing

A.b.fieldname1

yields the content of the first cell (10 double), but I cant seem to to be able to extract the entire fielname. Doing

c = cell2mat(struct2cell(A.b.fieldname1(1,1)))

yields the following error: Expected one output from a curly brace or dot indexing expression, but there were 10 results.

So how can I extract the data from this multi-layered structure ?

Thank you,

Answer by Stephen Cobeldick
on 22 Aug 2019 at 16:38

Edited by Stephen Cobeldick
on 23 Aug 2019 at 3:04

"How can i calculate the minimum of a given field (min_temp for example) ?"

You do not define what "the minimum" means for multiple vectors, which makes it hard to guesss what output you expect...

Method one: comma-separated list and cellfun:

For example:

>> vec = cellfun(@min,{pman_climatology.min_temp})

vec =

1.0000 4.6000 3.0000 3.0000 2.1000 2.5000 2.0000 2.0000 6.5000 1.5000 1.0000 1.5000 4.1000 1.0000

That gives the minimum value of the field min_temp for each element of the structure pman_climatology. Compare with the first few elements of pman_climatology:

>> min(pman_climatology(1).min_temp)

ans =

1

>> min(pman_climatology(2).min_temp)

ans =

4.6000

>> min(pman_climatology(3).min_temp)

ans =

3

Method two: anonymous function and arrayfun:

>> F = @(s)min(s.min_temp);

>> arrayfun(F,pman_climatology)

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 6 Comments

## Stephen Cobeldick (view profile)

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/477212-how-to-extract-data-from-a-multi-layered-structure#comment_738028

## Bluegin (view profile)

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/477212-how-to-extract-data-from-a-multi-layered-structure#comment_738045

## Guillaume (view profile)

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/477212-how-to-extract-data-from-a-multi-layered-structure#comment_738048

## Stephen Cobeldick (view profile)

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/477212-how-to-extract-data-from-a-multi-layered-structure#comment_738049

## Bluegin (view profile)

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/477212-how-to-extract-data-from-a-multi-layered-structure#comment_738055

## Stephen Cobeldick (view profile)

## Direct link to this comment

https://es.mathworks.com/matlabcentral/answers/477212-how-to-extract-data-from-a-multi-layered-structure#comment_738057

Sign in to comment.