Using Structure Array in Loop
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I am trying to create a for loop using data points stored within a structure array. I can't workout how I would do this. I'm new to coding so I tried the following but am getting errors regardless of what I try. Currently my first for loop runs providing me with WINDW1 (which is essentially just the sample rate). I then need to run the loop using each individual sample rate and its corresponding ODBA to calculate ODBA_1sec but it is here I get stuck as I can't workout how to get the loop to sync the right sample rate with its ODBA within the equation.
This is the code which works if I run it individually using my structure array - I change the (3) depending on which sample frequency I want to run with.
%% Smooth the data for activity measures
% Sample rate used change (?) number to indiciate sample frequency 1 = 400; 2=200; 3=100; 4= 50; 5=25
sample_Hz = c_accData(3).sampleRate; %Change to the correct sample rate used
% Calculate the mean ODBA at 1 second intervals.
WINDW1 = 1*sample_Hz;
ODBA_1sec = accumarray(ceil((1:numel(c_accData(3).ODBA))/WINDW1)',c_accData(3).ODBA(:),[],@mean);
% Display message at the end of this section
disp('Data has been smoothed');
I then tried to make this into a for loop by bringing the structure array into one variable name which I could use within the equations. Matlab errors include
"Error using horzcat
Dimensions of matrices being
concatenated are not
consistent."
and that
"Variavle 'ODBA_Hz' might be set by a non-scalar operator."
sample_Hz = [c_accData(1).sampleRate c_accData(2).sampleRate c_accData(3).sampleRate c_accData(4).sampleRate c_accData(5).sampleRate];
for j = 1:sample_Hz
WINDW1 = 1*sample_Hz;
end
ODBA_Hz = [c_accData(1).ODBA c_accData(2).ODBA c_accData(3).ODBA c_accData(4).ODBA c_accData(5).ODBA];
for k = 1:ODBA_Hz
ODBA_1sec = accumarray(ceil((1:numel(ODBA_Hz))/WINDW1)',ODBA_Hz(:),[],@mean);
disp('Data has been smoothed');
end
I'm sure it's a simple task just not one I have learnt yet so I hope someone can help. Thanks in advance.
Justine
Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!