MATLAB: Connecting points in scatter3 plot

scatter3

hi there. I am trying to connect points in a scatter3 plot. i tried using line, but that is applicable for 2D plot. but the data contains 3 dimensions. can anyone please tell me which command should i use after the line to connect points? thanks in advance.
scatter3(objlist.r_c(1,1,:),objlist.r_c(2,1,:),objlist.r_c(3,1,:))

Best Answer

OK, now I understand the problem. The issue isn't that the data is representing 3-dimensional points, but that it's stored in a 3-D array. So you need to squeeze or reshape your data into vectors:
x = objlist.r_c(1,1,:);
x = x(:);
y = objlist.r_c(2,1,:);
y = y(:);
z = objlist.r_c(3,1,:);
z = z(:);
scatter3(x,y,z);
line(x,y,z)
% or plot3(x,y,z,'o-')
Or
x = squeeze(objlist.r_c(1,1,:));
y = squeeze(objlist.r_c(2,1,:));
z = squeeze(objlist.r_c(3,1,:));
scatter3(x,y,z);
line(x,y,z)