Struct contents reference from a non-struct array object.
Show older comments
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
Stephen23
on 14 Dec 2018
@Justine Pearce: please show us the complete error message. This means all of the red text.
Justine Pearce
on 14 Dec 2018
Adam
on 14 Dec 2018
Use the Stop/Pause on errors debugging and then on whatever line it stops on examine whatever variables are being accessed that are expected to be structs and you will find the problem in seconds.
Image Analyst
on 14 Dec 2018
That's not all the red text - it's just a snippet from it. The complete error message will have things like the line number, the actual line of code, etc.
It may be because c_rate is not a structure. What does this show, if you put it in there before it throws the error:
whos c_rate
Cris LaPierre
on 14 Dec 2018
Could you share your variable Fs? Easiest is to save it in a mat file and attach the mat file to your post.
Justine Pearce
on 14 Dec 2018
Justine Pearce
on 14 Dec 2018
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!