Need help with indexing in a nested for loop
Show older comments
Hi everyone. I have to write a code that will apply a narrow band-pass filter around each frequency and stack the ccfs for different test velocities: This is my attempt at writing the code but it gives me the error Assingment has more non-singleton rhs dimensions than non-singleton subscripts. I would appreciate any kind of help. Thank you.
% ccf is a NxM matrix (153x4001), with N the amount of cross-correlation pairs and M the amount of time samples.
%ccf are cross-correlation functions
load ccf
%Define the testing velocity range
testVelocity = 100:1:300;
freqVec = 7:40;
sampling_rate = 400;
% dist is a Nx1 vector with the interstation distance for each of the N pairs
dist = nonzeros(flipud(tril(repmat((85:-5:5)',1,85/5))))';
DispCurve=zeros(length(testVelocity), length(freqVec));
% Loop over frequencies
for fInd = 1:length(freqVec)
freq=freqVec(fInd);
[A,B]=butter(4,[7, 40]./(sampling_rate/2));
ccf_filtered=filtfilt(A,B,ccf); % Narrow band-pass filter applied to each ccf
% Loop over all velocities
for ind = 1:length(testVelocity)
% find the sample in each ccf that corresponds to the test velocity
testVsamplePositiveLag=(M-1)/2 + round(dist./testVelocity(ind));
testVsampleNegativeLag=(M-1)/2 - round(dist./testVelocity(ind));
DispCurve(ind,fInd)=sum(ccf_filtered(:,testVsamplePositiveLag)) + sum(ccf_filtered(:,testVsampleNegativeLag)); % sum positive and negative lag times
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!