【问题标题】:Align right-shifted waveforms (action potentials)对齐右移波形(动作电位)
【发布时间】:2018-07-30 15:14:31
【问题描述】:

enter image description here

我的代码难以按最小峰值点对齐右移波形。在左移中,我将所需最小点与波形左侧给定点之间的索引差异复制,然后在对齐波形后删除那些额外的点。但是,相同的技术不适用于右移的技术。任何帮助将非常感激!输入 (vals) 是任何 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

结束

  • 列表项

【问题讨论】:

    标签: matlab alignment waveform


    【解决方案1】:

    是否将 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
    

    【讨论】:

    • 看起来虽然有很多波形,但由于某种原因它不起作用。你知道为什么会这样吗?我在上面附上了一个例子
    • 所需的输出是什么?它与您附加的图像有何不同?
    • 它应该在峰值处对齐,而图中所示的在我看来是非常毁容的一次波形
    • 抱歉,我无法仅根据图像重现问题,需要一个简单的可重现测试用例才能继续(例如未正确对齐的 2x97 或更小的输入矩阵)。
    猜你喜欢
    • 2011-11-05
    • 2019-11-17
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 2021-11-01
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多