finding size of arrays in nested structs

7 views (last 30 days)
Noel
Noel on 12 Nov 2013
Commented: Noel on 12 Nov 2013
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
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?
Noel
Noel on 12 Nov 2013
Blck.streams.Stim.data=[an array with 16 rows and over 2 million columns]
Blck.streams.EMGx.data=[an array with 16 rows and over 300,000 columns]
Blck.streams.ECGx.data=[an array with 1 row and over 100,000 columns]
Blck.streams.ACCx.data=[an array with 4 rows and over 30,000 columns]
basically, this is electrophysiology data produced by a data acquisition system that has inputs with different sampling rates. I am trying to figure out how to display each variable time locked to the Stim stream. I am to the point where I can display the plots individually, but now I am trying to set up a loop that displays all the selected variables in subplots. I need to know the number of rows because that represents the number of data channels. (I don't need to plot all 16 channels of EMGx data, only the last 4 are actually being used for measurement).

Sign in to comment.

Accepted Answer

Matt J
Matt J on 12 Nov 2013
Edited: Matt J on 12 Nov 2013
For example, the following is equivalent to size(Blck.streams.EMGx.data),
SelectedStreams={'Stim','EMGx','ECGx','ACCx'};
StreamIndex=2;
size(Blck.streams.(SelectedStreams{StreamIndex}).data)
  1 Comment
Noel
Noel on 12 Nov 2013
Awesome, curly brackets always get me.
Worked great!
Noel

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!