Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 在图形中移动曲线_Matlab_User Interface_Figure - Fatal编程技术网

Matlab 在图形中移动曲线

Matlab 在图形中移动曲线,matlab,user-interface,figure,Matlab,User Interface,Figure,如你所见,在第一张图片中,我有两个子图,两个相同,具有相同的曲线位置。但我需要更改其中一个子地块的曲线位置/或视角(现在不管是左视图还是右视图)。唯一有效的命令是CameraViewAngle,但这两个命令都会更改,我不知道为什么,我需要能够分别为每个命令更改。 如图2中所示,两个视图的视角都发生了变化。我宁愿只改变曲线位置 我使用的代码是: function [pointsQRS, pointsP, pointsT] = VCG (pointsQRS,pointsP,pointsT) gl

如你所见,在第一张图片中,我有两个子图,两个相同,具有相同的曲线位置。但我需要更改其中一个子地块的曲线位置/或视角(现在不管是左视图还是右视图)。唯一有效的命令是CameraViewAngle,但这两个命令都会更改,我不知道为什么,我需要能够分别为每个命令更改。 如图2中所示,两个视图的视角都发生了变化。我宁愿只改变曲线位置

我使用的代码是:

function [pointsQRS, pointsP, pointsT] = VCG (pointsQRS,pointsP,pointsT)


global ax1 ax2 h

figure('Name','Vektorkardiogram','NumberTitle','off','Color',[0.8 0.8 0.8])
ax1=subplot(1,2,1)
set(ax1,'Position',[0.10,0.11,0.3346590909090909,0.815],'CameraPosition',
[50.197132152696216,49.50150052184264,-7.57531754730548],'CameraTarget',
[0.4, 0.7, -0.33],'View',[-184.4219, -8.9326],'CameraViewAngle',
[9.256133109732078])

title('Vektorkardiogram')
hold on
grid on
view(3)

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');

 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);







ax2=subplot(1,2,2)
set(ax2,'Position',[0.565,0.11,0.33465909090909096,0.815],'CameraPosition',
[-13.197132152696216,-59.50150052184264,10.57531754730548])

title('Vektorkardiogram')
hold on
grid on
h=linkprop([ax1, ax2],
{'CameraPosition','CameraUpVector','XTick','YTick','ZTick'});

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');



   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);


linkaxes([ax1, ax2])
我需要它来改变它,以实现三维立体视图使用谷歌纸板。 提前感谢您的帮助

PS:例如,我想实现如图3所示的目标 但在这三幅图中,3D曲线没有连接,连接的意思是,当我移动其中一条曲线时,另一条曲线将以相同的方式移动


我设法解决了部分问题

更改
CameraViewAngle
,会修改曲线的大小,因此我决定保持曲线不变

不要设置角度,而是将
ax2
CameraPosition
设置为与
ax1
不同,但与目标保持相同的距离

我没有使用
linkprop
,而是使用并实现了一个回调函数,在修改
ax1
CameraPosition
时,设置
ax2
CameraPosition

阅读以下参考页:


代码如下:

function [pointsQRS, pointsP, pointsT] = VCG (pointsQRS,pointsP,pointsT)

%Clear global varabiles - for testing, we don't want any leftovers of ax1 and ax2.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear global
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Set some input data.
pointsQRS = 1:3:78;
pointsP = 1:2:92;
pointsT = 1:1:85;


%global ax1 ax2 h

fig1 = figure('Name','Vektorkardiogram','NumberTitle','off','Color',[0.8 0.8 0.8]);
ax1=subplot(1,2,1);

%Don't use view command, fill all parameters manually.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%view(ax1, 3)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Set ax1 parameters values to be same as result as after executing view(ax1, 3)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(ax1, 'XLim', [-0.5, 2.0], 'YLim', [-1, 3.0], 'ZLim', [-1.5, 1.0]);
set(ax1, 'Position',[0.13, 0.11, 0.3346590909090909, 0.815]);
set(ax1, 'CameraViewAngle', 10.339584907201974);
set(ax1, 'CameraTarget', [0.75, 1.0, -0.25]);
set(ax1, 'View',[-184.4219, -8.9326]);
set(ax1, 'DataAspectRatio', [1, 1.6, 1.0]);
set(ax1, 'PlotBoxAspectRatio', [1, 0.95521169259094, 0.8871534463389812], 'PlotBoxAspectRatioMode', 'Manual');
set(ax1, 'CameraPosition', [-10.664276793913514,-22.800600208737055,10.57531754730548]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


ax2 = subplot(1,2,2);

%Set ax2 parameters values to be same as result as after executing view(ax2, 3)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(ax2, 'XLim', [-0.5, 2.0], 'YLim', [-1, 3.0], 'ZLim', [-1.5, 1.0]);
set(ax2, 'Position',[0.5703409090909091, 0.11, 0.3346590909090909, 0.815]);
set(ax2, 'CameraViewAngle', 10.339584907201974);
set(ax2, 'CameraTarget', [0.75, 1.0, -0.25]);
set(ax2, 'View',[-184.4219, -8.9326]);
set(ax2, 'DataAspectRatio', [1, 1.6, 1.0]);
set(ax2, 'PlotBoxAspectRatio', [1, 0.95521169259094, 0.8871534463389812], 'PlotBoxAspectRatioMode', 'Manual');
set(ax2, 'CameraPosition', [-10.664276793913514,-22.800600208737055,10.57531754730548]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%Move the camera of ax2 to be in different position compared to ax1, but keep the same distance from the Target.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cameraTarget = [0.75, 1.0, -0.25];
cameraPosition = [-10.664276793913514,-22.800600208737055,10.57531754730548];
V = cameraPosition - cameraTarget;
newV = V + [-10, 0, 0];
newV = newV/norm(newV)*norm(V);
newCameraPosition = cameraTarget + newV;
set(ax2, 'CameraPosition', newCameraPosition);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Store ax1 and ax2 in figure UserData
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(fig1, 'UserData', [ax1, ax2]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Set axes ax1 as active axes.
axes(ax1);


title('Vektorkardiogram')
hold on
grid on

%Move view(3) up
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%view(3)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Use plot3 from Matlab example (fill curve with some data).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%t = -3*pi:pi/50:3*pi;st = sin(t)*2;ct = cos(t)*2;plot3(st,ct,t/6)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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');

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);

%ax2 = subplot(1,2,2); Moved up, axes(ax2) is used instead.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ax2 = subplot(1,2,2);
axes(ax2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


title('Vektorkardiogram')
hold on
grid on

%Move linkprop to the end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%h=linkprop([ax1, ax2],{'CameraPosition', 'CameraUpVector', 'XTick', 'YTick', 'ZTick'});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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

%Use plot3 from Matlab example (fill curve with some data).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%t = -3*pi:pi/50:3*pi;st = sin(t)*2;ct = cos(t)*2;plot3(ax2, st,ct,t/6)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


xlabel('Vx');ylabel('Vy');zlabel('Vz');

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);

%view(ax1, 3)
%view(ax2, 3)


%Matalb gives warning message: linkaxes requires 2-D axes as input. Use linkprop for generic property linking.
%call linkprop here instead.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%linkaxes([ax1, ax2])
%h=linkprop([ax1, ax2],{'CameraPosition', 'CameraUpVector', 'XTick', 'YTick', 'ZTick'});

%Don't link CameraPosition - it is linked by "listener" implementation
linkprop([ax1, ax2],{'CameraUpVector', 'XTick', 'YTick', 'ZTick'});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Add "listener", instead of using linkprop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
addlistener(ax1, 'CameraPosition', 'PostSet', @Ax1CameraPositionCallback);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Display cameratoolbar
cameratoolbar


function Ax1CameraPositionCallback(src, evnt, ~)
ax1 = evnt.AffectedObject;

fig1 = get(ax1, 'Parent');
userData = get(fig1, 'UserData');
ax2 = userData(2);

%Move the camera of ax2 to be in different position compared to ax1, but keep the same distance from the Target.
cameraTarget = get(ax1, 'CameraTarget');
cameraPosition = get(ax1, 'CameraPosition');

V = cameraPosition - cameraTarget;
newV = V + [-10, 0, 0];
newV = newV/norm(newV)*norm(V);
newCameraPosition = cameraTarget + newV;

set(ax2, 'CameraPosition', newCameraPosition);

尝试不调用
linkaxes([ax1,ax2])
。这样可以解决问题,但出现了另一个问题,左图要小得多。请参见问题中的编辑,最后一张图片,左侧的figure/3D曲线要小得多。你知道为什么picutre比另一个小吗?你能让你发布的代码在其他机器上执行吗?将一些数据放入
pointsQRS、pointsP、pointsT
中,并参考
mArrow3
函数。您可以在此处下载mArrow3函数:我的代码中唯一可以使用的修改如下:对于我做的数据:pointsQRS=1:3:78;点SP=1:2:92;pointsT=1:1:85;我在GUI中选择的特定数据,因此无法填写我正在使用的确切数据。但是mArrow3函数所做的轴的视角也很明显。我设法得到了一个部分解决方案,请让我知道它是否仍然相关。我可能有一个误解,我不想要一个单独的控件,相同的控件,只需更改曲线的视角。我已经做了你的建议,它是连接的,但再次,左边的3D曲线更小,它在移动时改变了它的大小。PS:我需要保持相同的大小,保持连接,只是改变曲线的位置/视角。今天晚些时候你有时间吗?