Reference to non-existent field
Ältere Kommentare anzeigen
I can't work out why I keep getting reference to non-existent field. I've defined t_accData and I can't see that it is used in any other function so I'm confused:
%% 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
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)
%Get current sample rate within loop
c_rate = Fs(j);
%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 doe 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 t_accData to a Mat file
save ([filename(1:end-4) '_resample_rawData_Fs_' num2str(c_rate) 'hz.mat', 't_accData'], 't_accData');
%Takes all files of t_accData and combines them into one structure
%with all sample frequencies within it. The delets t_accData.
c_accData(j) = 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
4 Kommentare
Walter Roberson
am 11 Dez. 2018
You appear to be hitting the branch where the file already exists. You should re-check whether the file contains the variable c_accData like the comment says, or if it contains t_accData like you try to access.
Note: we recommend that you assign
filename = [filename(1:end-4) '_resample_rawData_Fs_' num2str(c_rate) 'hz.mat'];
and then use the variable, instead of rebuilding the name every time you use it.
I would recommend that you replace
filename(1:end-4)
with the more robust
[~,F] = fileparts(filename)
Also replace all of those string concatenations with sprintf, which would make it easier to spot bugs, such as this strange filename input to save:
[filename(1:end-4) '_resample_rawData_Fs_' num2str(c_rate) 'hz.mat', 't_accData']
Most probably you did not want that trailing t_accData in the file extension. Better:
sprintf('%s_resample_rawData_Fs_%dhz.mat',F,c_rate)
Justine Pearce
am 11 Dez. 2018
Antworten (0)
Kategorien
Mehr zu App Building finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!