簡體   English   中英

Matlab 行代碼錯誤

[英]Matlab line code error

我們使用 matlab 來分析我們心臟病患者的 hrv 結果。我們能夠得到我們需要的波形,但它在代碼行 67 中顯示錯誤。請幫助。

x1 = load('ecg3.dat'); 
x2=x1; fs = 1000; % Sampling rate
N = length (x2); % Silength
t = [0:N-1]/fs; % tiidx
figure(1)

subplot(2,1,1)
plot(t,x1)
xlabel('second');ylabel('Volts');title('Input ECG Signal')
% Cancellation DC drift and normalization
x1 = x1 - mean (x1 ); % cancel DC conponents
x1 = x1/ max( abs(x1 )); % normalize to one

subplot(4,1,2)
plot(t,x1)
xlabel('second');ylabel('Volts');title(' ECG Signal after cancellation DC drift and 
normalization')
% Low Pass Filtering
b=[1 0 0 0 0 0 -2 0 0 0 0 0 1]; a=[1 -2 1];
h_LP=filter(b,a,[1 zeros(1,12)]); % transfer function of LPF
x2 = conv (x1 ,h_LP);
x2 = x2 (6+[1: N]); %cancel delay
x2 = x2/ max( abs(x2 )); % normalize , for convenience .

subplot(4,1,3)
plot([0:length(x2)-1]/fs,x2)
xlabel('second');ylabel('Volts');title(' ECG Signal after LPF')
xlim([0 max(t)])
% High Pass Filtering
b = [-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 -32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1];
a = [1 -1];
h_HP=filter(b,a,[1 zeros(1,32)]); % impulse response of HPF
x3 = conv (x2 ,h_HP);
x3 = x3/ max( abs(x3 ));

subplot(4,1,4)
plot([0:length(x3)-1]/fs,x3)
xlabel('second');ylabel('Volts');title(' ECG Signal after HPF')**LINE67**
xlim([0 max(t)])
% Derivative Filter
% Make impulse response
h = [-1 -2 0 2 1]/8;
% Apply filter

x4 = conv (x3 ,h);
x4 = x4 (2+[1: N]);
x4 = x4/ max( abs(x4 ));
figure(2)

subplot(4,1,1)
plot([0:length(x4)-1]/fs,x4)
xlabel('second');ylabel('Volts');title(' ECG Signal after Derivative')
% Squaring
x5 = x4 .^2;
x5 = x5/ max( abs(x5 ));

subplot(4,1,2)
plot([0:length(x5)-1]/fs,x5)
xlabel('second');ylabel('Volts');title(' ECG Signal Squarting')
% Moving Window Integration
% Make impulse response
h = ones (1 ,31)/31;
Delay = 15; % Delay in samples
% Apply filter
x6 = conv (x5 ,h);
x6 = x6 (15+[1: N]);
x6 = x6/ max( abs(x6 ));

subplot(4,1,3)
plot([0:length(x6)-1]/fs,x6)
xlabel('second');ylabel('Volts');title(' ECG Signal after Averaging')
% Find QRS Points Which it is different than Pan-Tompkins algorithm
max_h = max(x6);
thresh = mean (x6);
poss_reg =(x6>thresh*max_h)';
left = find(diff([0 poss_reg'])==1);
right = find(diff([poss_reg' 0])==-1);
left=left-(6+15); % cancel delay because of LP and HP
right=right-(6+15);% cancel delay because of LP and HP
left=abs(left);
right=abs(right);
for i=1:length(left)
[R_value(i) R_loc(i)] = max( x1(left(i):right(i)) );
R_loc(i) = R_loc(i)-1+left(i); % add offset
[Q_value(i) Q_loc(i)] = min( x1(left(i):R_loc(i)) );
Q_loc(i) = Q_loc(i)-1+left(i); % add offset
[S_value(i) S_loc(i)] = min( x1(left(i):right(i)) );
S_loc(i) = S_loc(i)-1+left(i); % add offset

end

subplot(4,1,4)
plot (t,x1,t(R_loc) ,R_value , 'r^')
% there is no selective wave
Q_loc=Q_loc(find(Q_loc~=0));
R_loc=R_loc(find(R_loc~=0));
S_loc=S_loc(find(S_loc~=0));

values=x2(R_loc);
% 1 beat/sec x 60 sec/min = 60 beats/min. 
%%R-R interval using diffrence operation method

tiscl=t(2)-t(1);
px=diff(R_loc);
d_tms=find(diff(R_loc)>200);
d_men=mean(px(d_tms)); 
beat=d_men*tiscl;
heart_rate=1/beat*60;
fprintf('%2.1f seconds/beat\n',beat);
rs=sprintf('Heart Rate= %2.1f beats per minit \n',heart_rate);

**

???錯誤使用 ==> horzcat

 CAT arguments dimensions are not consistent. Error in ==> Untitled at 67 left = find(diff([0 poss_reg']) ==1);

**

這是在子圖 (4,1,4) 處收到的錯誤消息,不知道如何糾正此錯誤。 由於我們的項目因此暫停,請提供幫助。

錯誤信息與“子圖(4,1,4)”無關。 [0 poss_reg']是導致錯誤的原因。 horzcat意思是“水平連接”,這就是你要在那里做的事情。 但是, poss_reg'可能是一列。 因此,您不能將其與零水平連接。 (有關更多信息,請參閱help horzcat )。

如果您不確定要使用行向量還是列向量,則一種選擇是使用 (:) 強制列方向並vertcat

[0; poss_reg(:)] 

更一般地說,您應該使用dbstop if error或其他 MATLAB 調試工具,並在發生錯誤時檢查變量的大小和類型。

嘗試 :

left  = find(diff([0; poss_reg],1,1)==1);  % remember to zero pad at start
right = find(diff([poss_reg; 0],1,1)==-1); % remember to zero pad at end

祝你好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM