我在下面有这个功能,它可以完美地满足我的需要:
function [pointsQRS, pointsP, pointsT] = VCG (pointsQRS,pointsP,pointsT)
global ax1 ax2 h
figure('Name','Vektorkardiogram','NumberTitle','off','Color',[0.8 0.8 0.8])
%% first axes
ax1=subplot(1,2,1);
set(ax1,'Position',[0.1,0.2,0.3,0.7])
title('Vektorkardiogram')
hold on
grid on
axis vis3d
view([0 10])
plotCurve
mArrow3([1.5 2 -1],[-0.5, 2, -1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
mArrow3([1.5 2 -1],[1.5, -0.5, -1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
mArrow3([1.5 2 -1],[1.5, 2, 1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
text(-0.5, 2, -1, 'Vx','FontSize',12);
text(1.5, -0.5, -1, 'Vy','FontSize',12);
text(1.5, 2, 1, 'Vz','FontSize',12);
%% second axes
ax2=subplot(1,2,2);
set(ax2,'Position',[0.6,0.2,0.3,0.7])
title('Vektorkardiogram')
hold on
grid on
axis vis3d
view([10 10])
plotCurve
function plotCurve
for i=2:size(pointsQRS,1)
if mod(i,2)==0
QRS=plot3(pointsQRS([i-1:i],1),pointsQRS([i-
1:i],2),pointsQRS([i-1:i],3),'-g','LineWidth',1);
else
plot3(pointsQRS([i-1:i],1),pointsQRS([i-
1:i],2),pointsQRS([i-1:i],3),'Color',[0 0 0],'LineWidth',1);
end
end
for i=2:size(pointsT,1)
if mod(i,2)==0
T=plot3(pointsT([i-1:i],1),pointsT([i-1:i],2),pointsT([i-
1:i],3),'-r','LineWidth',1);
else
plot3(pointsT([i-1:i],1),pointsT([i-1:i],2),pointsT([i-
1:i],3),'Color',[0 0 0],'LineWidth',1);
end
end
for i=2:size(pointsP,1)
if mod(i,2)==0
P=plot3(pointsP([i-1:i],1),pointsP([i-1:i],2),pointsP([i-
1:i],3),'-b','LineWidth',1);
else
plot3(pointsP([i-1:i],1),pointsP([i-1:i],2),pointsP([i-
1:i],3),'Color',[0 0 0],'LineWidth',1);
end
end
xlabel('Vx');ylabel('Vy');zlabel('Vz');
end
mArrow3([1.5 2 -1],[-0.5, 2, -1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
mArrow3([1.5 2 -1],[1.5, -0.5, -1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
mArrow3([1.5 2 -1],[1.5, 2, 1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
text(-0.5, 2, -1, 'Vx','FontSize',12);
text(1.5, -0.5, -1, 'Vy','FontSize',12);
text(1.5, 2, 1, 'Vz','FontSize',12);
%% Slider Rotace
S = uicontrol('Style','slider',...
'Position',[10 10 300 20],...
'Max',180,...
'Min',-180,...
'Value',0,...
'SliderStep',[1/360 1/360]);
LS=addlistener(S,'ContinuousValueChange',@slider_callback);
set(S,'UserData',LS)
end
function slider_callback(hObject,eventData)
global ax1 ax2
val = get(hObject,'value');
view(ax1,[val,10])
view(ax2,[val+10,10])
end
但是当我更改代码时,简化了,因为在其他功能中我只需要 pointsT ,它会给出我在图片中的错误。 简化的代码是:
function pointsT = VCG_T (pointsT)
global ax1_T ax2_T h_T
figure('Name','Vektorkardiogram','NumberTitle','off','Color',[0.8 0.8 0.8])
%% first axes
ax1_T=subplot(1,2,1);
set(ax1_T,'Position',[0.1,0.2,0.3,0.7])
title('Vektorkardiogram')
hold on
grid on
axis vis3d
view([0 10])
plotCurve
mArrow3([1.5 2 -1],[-0.5, 2, -1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
mArrow3([1.5 2 -1],[1.5, -0.5, -1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
mArrow3([1.5 2 -1],[1.5, 2, 1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
text(-0.5, 2, -1, 'Vx','FontSize',12);
text(1.5, -0.5, -1, 'Vy','FontSize',12);
text(1.5, 2, 1, 'Vz','FontSize',12);
%% second axes
ax2_T=subplot(1,2,2);
set(ax2_T,'Position',[0.6,0.2,0.3,0.7])
title('Vektorkardiogram')
hold on
grid on
axis vis3d
view([10 10])
plotCurve
for i=2:size(pointsT,1)
if mod(i,2)==0
T=plot3(pointsT([i-1:i],1),pointsT([i-1:i],2),pointsT([i-
1:i],3),'-r','LineWidth',1);
else
plot3(pointsT([i-1:i],1),pointsT([i-1:i],2),pointsT([i-
1:i],3),'Color',[0 0 0],'LineWidth',1);
end
end
mArrow3([1.5 2 -1],[-0.5, 2, -1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
mArrow3([1.5 2 -1],[1.5, -0.5, -1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
mArrow3([1.5 2 -1],[1.5, 2, 1], 'stemWidth',
0.005,'color','red','facealpha',0.3);
text(-0.5, 2, -1, 'Vx','FontSize',12);
text(1.5, -0.5, -1, 'Vy','FontSize',12);
text(1.5, 2, 1, 'Vz','FontSize',12);
%% Slider Rotace
S = uicontrol('Style','slider',...
'Position',[10 10 300 20],...
'Max',180,...
'Min',-180,...
'Value',0,...
'SliderStep',[1/360 1/360]);
LS=addlistener(S,'ContinuousValueChange',@slider_callback);
set(S,'UserData',LS)
end
function slider_callback(hObject,eventData)
global ax1_T ax2_T
val = get(hObject,'value');
view(ax1_T,[val,10])
view(ax2_T,[val+10,10])
end
我完全不知道为什么简化的代码不起作用,可能我忽略了一些东西。 你能给我一个提示吗?
答案 0 :(得分:1)
您已删除该行function plotCurve
。这是一个重要的,因为它定义了主函数VCG
调用的局部函数。在您的缩减示例中,此函数不再存在,因为您删除了其标题。这就是你看到这个错误的原因。
只需将其放回(在第一个循环之前),然后就可以了。