but it still just prints the matrix horizontally in the command window
Yes. because that's exactly how you're asking matlab to display it. With
fprintf('%d ', array_of_any_shape)
matlab just replicates the format string until the end of the array. So it's equivalent to:
fprintf('%d %d %d %d ... as many as necessary', array_of_any_shape(:))
The simplest way to display your array according to its shape is to use disp, so:
and you're done. If you really want to use fprintf or sprintf, then you need to use:
fprintf('%d %d %d\n', coordsOut.');
Finally, note that in
coordsOut=vertcat([coordsOut; [xi(j), yi(j), zi(j)]]);
the vertcat does nothing (you only pass it one argument, so it's got nothing to concatenate) and the second sets of [] is also useless.
coordsOut=[coordsOut; xi(j), yi(j), zi(j)];
Best Answer