我的代码在按最小峰值点对齐右移波形时遇到困难。在向左移动时,我将所需的最小点与给定的最小点之间的索引差复制到波形的左侧,然后在对齐波形后删除那些多余的点。但是,相同的技术不适用于右移的技术。任何帮助将非常感激!输入(值)是任何n x 97矩阵。
function [vals] = align_wvs(wvs)
%Align_wvs - Align waveforms to minimum point
%
%align_wvs(wvs)
%
%wvs - matrix of waveforms
%
%Returns 'vals' - newly aligned matrix of waveforms
wvfrms = (wvs*10^6); %convert to microvolts
wvfrms = wvfrms(:,all(~isnan(wvfrms)));
min_pt = min(wvfrms(:)); %find minimum point in wvs
[~,col] = find(wvfrms==min_pt); %find index of min poin
if numel(col)>1
col = col(1);
end
%and that of other wvfrms
vals = zeros(size(wvfrms)); %matrix of size wvfrms, vals
for i = 1:size(vals,1) %for length of input
vals(i,:) = wvfrms(i,:); %copy og wvfrm into vals
nums = vals(i,:); %get second copy
ind_min = min(nums);
[~,colmin] = find(nums==ind_min);
diff_col = col-colmin;
if (diff_col~=0) %if difference is not = 0
if (diff_col>0) %if wvfrm is shifted to the left
inds = nums(1:diff_col); %copy first n values of nums, where n is diff_rows
new_length = length(nums)+length(inds); %extend wvfrm by amount ind
new_vals = zeros(1,new_length); %create new array of size new_length
new_vals(1:(diff_col)) = inds; %add inds to begining of new array
new_vals(diff_col+1:end) = nums; %add nums to rest of array
new_vals(1:(diff_col)) = [];%delete diff_rows-1 values from end
vals(i,:) = new_vals; %add to values
else %if wvfrm is shifted to the right
inds = nums(end+(diff_col+1):end); %copy last n values of nums, where n is diff_rows
new_length = length(nums)+length(inds); %extend wvfrm by amount ind
new_vals = zeros(1,new_length); %create new array of size new_length
new_vals(end+(diff_col+1):end) = inds;%add inds to end of new array
new_vals(1:(end+(diff_col))) = nums;%add nums to rest of array
new_vals(1:(diff_col*-1)) = []; %delete diff_rows-1 values from begining
vals(i,:) = new_vals; %add to values
end
end
end
结束
答案 0 :(得分:0)
是否用以下工作替换if(diff_col〜= 0)块?
if (diff_col~=0)
if (diff_col>0)
vals(i,:) = [zeros(1,diff_col) nums(1:(end-diff_col))];
else
vals(i,:) = [nums((-diff_col+1):end) zeros(1,-diff_col)];
end
end