简体   繁体   中英

How do I make a 3D line object in MatLab from xyz coordinates such that it is usable in a Procrustes Analysis?

I have a set of data made up of coordinates x, y, and z which I plot to create a 3D line. I want to perform a Procrustes Analysis to find the similarity between the shape of this 3D line and another default shape. When I try to use any shape analysis functions or Procrustes functions, it gives me an invalid handle error on the 3D plot input that I created to hold it, ie 'myLine'. How can I convert this 3D plot of coordinates to a usable object for Procrustes or some other function?

3D line created from the coordinates in code below.

myLine = plot3(GPS(:,8),GPS(:,9),GPS(:,10))

Below is the shape analysis function I'm trying to work with

function [f,g]=ShapeAnalysis(f,g)
% SHAPEANALYSIS(F,G) Plots the parameterised curves before and after
% each stage of translating, scaling and aligning. Outputs are
% parameterised curves ready for Procustes shape analysis.

LW = 'LineWidth'; FS = 'FontSize';
% Plot orignal
subplot(2,2,1)
plot(f,'r',LW,2), hold on, axis equal, plot(g,'k',LW,2)
title('Orignal',FS,16)

% Translate mean to 0.
f = f-mean(f); g = g-mean(g);
subplot(2,2,2)
plot(f,'r',LW,2), hold on, axis equal, plot(g,'k',LW,2)
title('After translation',FS,16)

% Scale so RMSD is 1.
f = f/norm(f); g = g/norm(g);
subplot(2,2,3)
plot(f,'r',LW,2), hold on, axis equal, plot(g,'k',LW,2)
title('After scaling',FS,16)

% Align major axis.
subplot(2,2,4)
% Find argument of major axis.
[~,fxmax]=max(abs(f)); [~,gxmax]=max(abs(g));
rotf=angle(f(fxmax)); rotg=angle(g(gxmax));
% Rotate both so major axis lies on the +ve real axis.
x = chebfun('x',[0,2*pi]);
f = exp(-1i*rotf)*f(mod(x+fxmax,2*pi));
g = exp(-1i*rotg)*g(mod(x+gxmax,2*pi));
plot(f,'r',LW,2), hold on, axis equal, plot(g,'k',LW,2)
title('After aligning',FS,16), hold off

end

edit: I guess an easier way to put it is how can I refer to the line created with one variable such that if I wrote 'plot(myLine)', where myLine = the line created by plot3(GPS(:,8),...), it will create the same line. This way I can pass the one variable to a comparison function. (to be clear, I am not having a problem with graphing the line, only manipulating it with only a reference to coordinates and no line equation)

edit: I am trying to pass myLine into shape analysis, along with say the equation for a circle to compare how closely myLine is to the second entry. So I enter:

>>myLine = plot3(GPS(:,8),GPS(:,9),GPS(:,10))
>>ShapeAnalysis(myLine,circle(0,0,1))

After entering this, I get the following error:

Error using plot
Invalid handle.

Error in ShapeAnalysis (line 9)
    plot(f,'r',LW,2), hold on, axis equal, plot(g,'k',LW,2)

I hope this clears my question up a bit.

You almost answered your own question: "How can I convert this 3D plot of coordinates to a usable object ...?" Like any object, you need a reference to it for manipulation:

myLine = plot3(GPS(:,8),GPS(:,9),GPS(:,10))

Now you can pass around myLine and see what you can do with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM