Struct contents reference from a non-struct array object.

15 views (last 30 days)
Hi, I have re-sampled data at different frequencies and now want to filter those new data sets. I have managed to do it as one structure (c_accData) but I need it to an ODBA for each frequency(Fs) which currently it isn't. To do this I then used c_rate instead of c_accData. c_rate = Fs(j) so stands for the current frequency. When I try and run this I get an error "struct content reference from a non-struct array object". I am assuming this is because c_rate isn't a non-struct array object but I'm not entirely sure how to go about this. Would love any feedback and help you guys have.
%% Filter the data
% [MD comment]: Note that you will have to change these filter settings for
% the very low sample rates (1Hz, 10Hz) because you can't filter with stop/pass
% frequencies above the sample frequency.
for j = 1:length(Fs)
c_rate = Fs(j)
%Check if re-sampled filtered files exist
if ~exist([filename(1:end-4) '_resample_filt_' num2str(c_rate) 'hz.mat'],'file')
% Run a bandpass filter
% Run the same filter specifications (above) for the each axis
stopBand = [0.001 10];
passBand = [0.5 5];
filtMode = 3;
%Create empty startTimes and endTimes arrays to check data alignment.
startTimes = [];
endTimes = [];
%if they don't exist, filter and create it
[X_filt] = ButterFilt(c_rate.x, stopBand, passBand, c_rate.sampleRate,filtMode);
[Y_filt] = ButterFilt(c_rate.y, stopBand, passBand, c_rate.sampleRate,filtMode);
[Z_filt] = ButterFilt(c_rate.z, stopBand, passBand, c_rate.sampleRate,filtMode);
% Calcualte Overall Dynamic Body Acceleration
ODBA = sqrt(X_filt.^2 + Y_filt.^2 + Z_filt.^2);
% [MD comment]: I suggest you avoid overwriting the raw data with the
% filter data, so you can compare the two and check that you are happy
% with the filter settings.
c_rate.x = X_filt;
c_rate.y = Y_filt;
c_rate.z = Z_filt;
c_rate.OBDA = ODBA;
c_rate.startTime = c_rate.timeStamp(1);
c_rate.endTime = c_rate.timeStamp(end);
startTimes = [startTimes c_rate.timeStamp(1)]; %#ok<*AGROW>
endTimes = [endTimes c_rate.timeStamp(end)];
% Save filtered data to a Mat file
save([filename(1:end-4) '_resample_filt_' num2str(c_rate) 'hz.mat']);
else
load ([filename(1:end-4) '_resample_filt_' num2str(c_rate) 'hz.mat']);
end
end
% % Clear unnecessary vectors
% clear X_filt Y_filt Z_filt
  7 Comments
Justine Pearce
Justine Pearce on 14 Dec 2018
%%
This is my code beforehand where I am re-sampling the original data into different frequencies. So the problem is with avoided if i use the c_accData but because this is one structure I'm not then getting individual ODBAs for each new frequency.
Import the accelerometer data (CWA file) into Matlab
% % Change name to file of interest
%filename = '39949_OR_C1.cwa';
filename = '39949_OR_C1_400hz.cwa';
% Use the AX3 function to import information of the accelerometer file
fileinfo = AX3_readFile(filename,'modality',[1, 0, 0],'info', 1);
% % Change the name of the structure that the accelerometere data will be imported to
% c_accData = AX3_readFile(filename, ...
% 'modality',[1, 0, 0], ...
% 'validPackets', fileinfo.validPackets, ...
% 'startTime', datenum('23-Jul-2018 12:53:00'), ... % Change the start time
% 'stopTime', datenum('23-Jul-2018 13:12:00')); % Change the end time
%% Load data, sample at multiple rates, save resulting as separate CSV files:
%Check to see if this step has been completed and saved previously
%If it has, load saved mat file to speed up processing
%Range of rates to resample:
Fs = [400 200 100 50 25]; %Arranging from High to low could be better for some plots
%resample in loop
for j = 1:length(Fs)
% [MD comment]: %Get current sample rate within the for loop
c_rate = Fs(j);
% [MD comment]: %check whether file exists (within the for loop)
if ~exist([filename(1:end-4) '_resample_rawData_Fs_' num2str(c_rate) 'hz.mat'],'file');
%If the file does not exist, create it:
%load acc data into a structure array with fields
% time, timestamp, x y z, sampleRate;
t_accData = resampleCWA(filename, c_rate); %#ok<*AGROW>
% Save c_accData to a Mat file
save([filename(1:end-4) '_resample_rawData_Fs_' num2str(c_rate) 'hz.mat'], 't_accData');
% [MD comment]: Note, above you were saving each sample frequency into separate files,
% but below you were treating 'c_accData' as a structure with all of the
% sample frequencies within it. So I have creating two separate variables
% to make this work.
c_accData(j) = t_accData;
clear t_accData;
else
%If the file does exist, load the existing file containing variable
%'c_accData'
tempStruct = load([filename(1:end-4) '_resample_rawData_Fs_' num2str(c_rate) 'hz.mat']);
c_accData(j) = tempStruct.t_accData;
clear tempStruct;
end %end of 'if/else' section
end % end of loading 'for loop'
The filter code works in this format but not in what I'm trying to do above:
%% Filter the data
% [MD comment]: Note that you will have to change these filter settings for
% the very low sample rates (1Hz, 10Hz) because you can't filter with stop/pass
% frequencies above the sample frequency.
% Run a bandpass filter
% Run the same filter specifications (above) for the each axis
stopBand = [0.001 10];
passBand = [0.5 5];
filtMode = 3;
%Create empty startTimes and endTimes arrays to check data alignment.
startTimes = [];
endTimes = [];
for j = 1:length(Fs)
[X_filt] = ButterFilt(c_accData(j).x, stopBand, passBand, c_accData(j).sampleRate,filtMode);
[Y_filt] = ButterFilt(c_accData(j).y, stopBand, passBand, c_accData(j).sampleRate,filtMode);
[Z_filt] = ButterFilt(c_accData(j).z, stopBand, passBand, c_accData(j).sampleRate,filtMode);
% Calcualte Overall Dynamic Body Acceleration
ODBA = sqrt(X_filt.^2 + Y_filt.^2 + Z_filt.^2);
% [MD comment]: I suggest you avoid overwriting the raw data with the
% filter data, so you can compare the two and check that you are happy
% with the filter settings.
c_accData(j).x = X_filt;
c_accData(j).y = Y_filt;
c_accData(j).z = Z_filt;
c_accData(j).OBDA = ODBA;
c_accData(j).startTime = c_accData(j).timeStamp(1);
c_accData(j).endTime = c_accData(j).timeStamp(end);
startTimes = [startTimes c_accData(j).timeStamp(1)]; %#ok<*AGROW>
endTimes = [endTimes c_accData(j).timeStamp(end)];
end
% Clear unnecessary vectors
clear X_filt Y_filt Z_filt
% Save filtered data to a Mat file
save([filename(1:end-4) '_resample_filt_25hz.mat']);
Justine Pearce
Justine Pearce on 14 Dec 2018
It is all the error code - it does usually provide a line but in this case it hasn't and I can't seem to debug it at certain points it won't let me

Sign in to comment.

Answers (0)

Categories

Find more on Applications 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!