Accessing data in sequential work space names and writing to matrix

Hello everyone,
I have a .MAT file from our DAQ unit that saves each data channel and header seperatly (Channel_i_Data = 40000x1 double) and (Channel_i_Header = 1x1 struct)
In this case i=47 different channels but can be more or less. I am trying to create a for loop that can access the n-th row of the 40000x1 double of each channel and input it into a matrix (essencially taking a snapshot of all the channels at the same time internal). I am able to load each channel and write them individually but I dont know how to make it progress through all of them in the for loop.
for k = 1:channels
channel = sprintf('Channel_%d_Data',k);
S = load(filename,channel);
Var = S.Channel_????; % <-----issue is here
Data(k,1) = Var(row,1);
end

 Accepted Answer

Var = S.(channel); % <-----issue is here

2 Comments

Thank you so much! I could not find this simple answer anywhere!
It is called dynamic field names. Searching in doc should find it.
structName.(dynamicExpression)

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!