How to access elements of nested structures

2 views (last 30 days)
Hi all,
I have a nested structure. A 1*1 struct(data) contains a 1*1 struct(metadata) and a 245*1 struct(results). I want to access the column 'id' within a 245 *1 struct. Can anyone teach me how to do that? the nested structure is attached here.

Accepted Answer

Image Analyst
Image Analyst on 29 Dec 2022
Try this:
s = load('data.mat')
s = struct with fields:
data: [1×1 struct]
id = {s.data.results.id}'
id = 245×1 cell array
{'GHCND:USC00310090'} {'GHCND:USC00310184'} {'GHCND:USC00310212'} {'GHCND:USC00310241'} {'GHCND:USC00310286'} {'GHCND:USC00310356'} {'GHCND:USC00310375'} {'GHCND:USC00310506'} {'GHCND:USC00310576'} {'GHCND:USC00310645'} {'GHCND:USC00310674'} {'GHCND:USC00310724'} {'GHCND:USC00310750'} {'GHCND:USC00310843'} {'GHCND:USC00310901'} {'GHCND:USC00310982'} {'GHCND:USC00311055'} {'GHCND:USC00311156'} {'GHCND:USC00311165'} {'GHCND:USC00311221'} {'GHCND:USC00311222'} {'GHCND:USC00311239'} {'GHCND:USC00311248'} {'GHCND:USC00311420'} {'GHCND:USC00311429'} {'GHCND:USC00311515'} {'GHCND:USC00311535'} {'GHCND:USC00311564'} {'GHCND:USC00311578'} {'GHCND:USC00311606'}

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!