MATLAB: To save Output array in the arranged form

Hello Brothers and sisters!
Actually my problem is that I wish to save the output data from my code in an arranged form, Although I am getting the arranged form of my output data but the problem is that it only appears when I open that output.txt file in Matlab and when i wants to open that text file out of the matlab environment, It just gives me numbers without any order and the shape of matrix no more exists.
The second thing is can we save our data (arrays) directly into an excel sheet? If yes, Please tell me the way
I shall be thankful.

Best Answer

For the first question:
You might currently have an fopen() statement that looks something like
fid = fopen('SomeFileName.txt', 'w');
If you do, then change that line to
fid = fopen('SomeFileName.txt', 'wt');
Possibly instead you are using dlmwrite() with something that looks like
dlmwrite('SomeFileName.txt', YourArray);
If you do, then change that line to
dlmwrite('SomeFileName.txt', YourArray, 'Newline', 'pc');
Possibly instead you are using csvwrite() with something that looks like
csvwrite('SomeFileName.txt', YourArray);
If you do then change the csvwrite() to dlmwrite and add the 'Newline', 'pc' option,
dlmwrite('SomeFileName.txt', YourArray, 'Newline', 'pc');
For the second question:
You can use xlswrite() to write directly into .xls or .xlsx format.
Related Question