MATLAB: How to print the data to a .txt file

data to textfprintf

Haven't been able to make sense of the info on MathWorks. All I'm trying to do is write the outputted vector from my function to a text file.
Here's what I've tried
fileID=fopen('solution.txt');
fprintf(fileID,'%e',x);
x is the outputted 1×5 or 1×10 vector. Just want to put it into a text. Any help on what I'm doing wrong?

Best Answer

Note that if all you want to do is write a single array to a text file and close the file, then dlmwrite is much simpler:
dlmwrite('solution.txt', x); %that's all, although you can go fancier if you want