MATLAB: How to draw perpendicular/orthogonal lines

axesaxisfigureMATLABorthogonalorthonormateperpendicular

Hello community! Given 4 points in a 3D space (with known coordinates), I want to draw perpendicular/orthogonal (and aesthetic) axes. So far, I managed to "bypass" the solution provided that I only show the figure and not the code. Picture down below shows my result, using this piece of code:
lx1=[c1(1) c2(1) (c1(1)+c2(1))/2 c3(1) (c1(1)+c2(1))/2 c4(1)];
ly1=[c1(2) c2(2) c1(2) c3(2) c1(2) c4(2)];
lz1=[c1(3) c2(3) c1(3) c3(3) c1(3) c4(3)];
line(lx1, ly1, lz1)
Where c1, c2, c3, c4 are arrays containing x,y,z values of each point.
While this piece of code works for that particular set of values (again, stressing that nobody sees the code behind that result), I need something which will work for sets of random values. Picture down below states the obvious.
Any suggestions/ideas, dear friends?

Best Answer

As my code was apparently a full answer to your question, I'll repost my comment as an answer so you can accept it.
origin=[0 0 0];
lx=[c1(1),c2(1),c3(1),c4(1)];
ly=[c1(2),c2(2),c3(2),c4(2)];
lz=[c1(3),c2(3),c3(3),c4(3)];
%let all points go through the origin
lx=[lx;origin(1)*ones(size(lx))];
ly=[ly;origin(2)*ones(size(ly))];
lz=[lz;origin(3)*ones(size(lz))];
[lx,ly,lz]=deal(lx(:),ly(:),lz(:));
line(lx, ly, lz)