Nested for loop for filtering times?

2 次查看(过去 30 天)
Hi all,
so I'm writing a script that takes in a bunch of data from two 'channels' (C1 and C2) which have specific times allocated in an array. As the code stands, the script 'filters' the data according to specified time windows in the second column of each channel. So I've specified the code to filter out all respective data with times that fall between integer values of 1000 and 2000. 1000 and 2000 can be altered by the user at the beginning of the code. This exacts out the filtered data and times linked in a double and writes it to two new channels (C7 and C8/filteredtimec1 and filteredtimec2). These newly filtered channels are then fed into another script for a calculation to be performed on it and eventually plotted. I've attached the code as it stands below:
rootdir = pwd;
if exist('pathname','var')
cd(pathname);
end
clearvars -except rootdir
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% input channels
channelA = 1;
channelB = 2;
% output channels
channelO1 = 'C7';
channelO2 = 'C8';
%Specify the time window of the microtime filter - middle integer is the
%window size i.e 500ps
filterstart = 1000;
filterstop = 2000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[filename, pathname]=uigetfile('*.mat', 'Header File');
importfilename = [pathname filename];
% open mat file
handles.mat = matfile(importfilename,'Writable',true);
% check if the mat file is a spot, if not then go to the next file
if ~strcmp(handles.mat.type,'spot')
woo = 999
sleep
end
channelAname = ['C' num2str(channelA)];
channelBname = ['C' num2str(channelB)];
filterlowvar1 = [channelO1 'filterlow'];
filterhighvar1 = [channelO1 'filterhigh'];
filterlowvar2 = [channelO2 'filterlow'];
filterhighvar2 = [channelO2 'filterhigh'];
%% MICROTIME FILTERING
% defines microtime for channel 1 and 2 **relies on ChannelA = 1, ChannelB
% = 2 (not the otherway round) for now**
filteredtimec1 = handles.mat.(channelAname)(:,:);
filteredtimec2 = handles.mat.(channelBname)(:,:);
%defines 'new' virtual channel for microtime 1 and 2, respectively and
%creates condition of filtering to ensure filtered values fall into
%user-defined window
logInd = filteredtimec1(:,2) < filterstop & filteredtimec1(:,2) > filterstart;
out1 = filteredtimec1(logInd,:);
logInd = filteredtimec2(:,2) < filterstop & filteredtimec2(:,2) > filterstart;
out2 = filteredtimec2(logInd,:);
handles.mat.(channelO1) = out1;
handles.mat.(channelO2) = out2;
handles.mat.(filterlowvar1) = filterstart;
handles.mat.(filterhighvar1) = filterstop;
handles.mat.(filterlowvar2) = filterstart;
handles.mat.(filterhighvar2) = filterstop;
Now I'm looking to make an amendment to this script to enable the user to specify a large time window such as 1000 up to 8000 in 500 integer increments whilst reading out new channels. For example it should loop through 1000 - 1500 and read out C7 and C8, then 1500 - 2000, reading out C9 and C10, 2000 - 2500 into C11 and C12, etc and the calculation script can then take in these channels and perform calculations on them. I imagine that I'd be better combining these scripts into the one script eventually as it's becoming gradually more complex. I'm really poor when it comes to using for loops and I'm finding that I'm confusing myself. I'd imagine that I'd need to set:
filterstart = (1000:500:8000)';
filterstop = (1500:500:8500)';
Or similarly but I'm not sure how to go about doing this, as well as a nested for loop:
for n = 1:length(filterstart)
for m = 1:length(filterstop)
Any clues would be greatly appreciated!!
Thanks

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by