finding size of arrays in nested structs
10 views (last 30 days)
Show older comments
I have been searching for the answer to this for a couple of days and haven't had any luck.
I have a data structure that includes another layer of structures, each of which includes multiple arrays:
Blck (1x1 struct)
epocs (1x1 struct)
snips (1x1 struct)
streams (1x1 struct)
Stim (1x1 struct)
data (16x2655114 single)
fs (2.4414e+04)
name ('stim')
Sign (1x1 struct)
EMGX (1x1 struct)
EMGR (1x1 struct)
.
.
.
I need to find the size of the array 'data'.
I have tried:
size(Blck.streams.Stim.data)
and I get the correct answer:
ans=16 2655114
but when I try to find the size in a loop I get the wrong answer:
size(strcat('Blck.streams.',SelectedStreams(StreamIndex),'.data'))
I get:
ans=1 1
I realized that
strcat('Blck.streams.',SelectedStreams(StreamIndex),'.data')
='Blck.streams.Stim.data'
so I tried:
Streams=SelectedStreams(StreamIndex)
size(sprintf('Blck.streams.%s.data',Streams))
Which yielded:
ans= 1 22
I don't know where that came from.
What I need is to find the size of Blck.streams.Stim.data, which should be:
ans=16 2655114
What command should I be using inside a loop that goes through all the streams and finds the size of the data arrays?
2 Comments
Doug Hull
on 12 Nov 2013
Can you show us the structure in simpler form?
a.b(1).c = [1 2; 3 4; 5 6]
a.b(2).c = [1; 2]
size(a.b(1).c)
size(a.b(2).c)
Or something similar so we are all working on the same structure and you can specifically show us what you are looking for?
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Structures 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!