How to delete a character with quotation marks from the following text file ?

1 view (last 30 days)
I want to delete the first row and first column from the attached text file by using the Matlab, which line command could help to achieve this task, I have alread tried "textscan", but I could not achieve this task ?!!
As a final result, I need to get a text file its content as the following:

Accepted Answer

Star Strider
Star Strider on 13 Feb 2016
Edited: Star Strider on 13 Feb 2016
This works:
fidi = fopen('Aiman Qais AQLuni1.txt','rt');
D = textscan(fidi, '%s%f%f%f', 'HeaderLines',1, 'CollectOutput',1);
NumericData = D{2};
Examine_Result = NumericData(1:5,:) % Look At The First 5 Lines Of ‘NumericData’ (This Line Can Be Deleted)
Examine_Result =
1.59432977791474 1.95836444054155 1
6.03431588230053 4.64158508276192 1
6.06213713168152 0.434638079095179 1
2.58438531054738 2.09769139940443 1
2.1037630806909 3.65927457968427 1
You can eliminate the top row by setting 'HeaderLines',1, and 'ColledtOutput',1 collects the numeric and string data separately. The string data are in the first cell, created with the '%s' as the first in the format descriptor string. To delete the top row and first column then, all you need is in the ‘NumericData’ double array in my code.
EDIT — Added the ‘Examine_Result’ line and associated output.
  3 Comments
Aiman Qais
Aiman Qais on 13 Feb 2016
Edited: Aiman Qais on 13 Feb 2016
What is the best option to save the output of the above command lines in an another text file, could you please post it here Mr. Star Strider ?
Star Strider
Star Strider on 13 Feb 2016
My pleasure!
There are several options, depending on what you want to do with it. If you are only going to use it with MATLAB, I would save it as a .mat file:
save('AQLuni1.mat', 'NumericData');
To use it in other applications, a comma-separated file would work:
csvwrite('AQLuni1.csv', NumericData);
See also xlswrite and dlmwrite if you want to write to an Excel file or a file with other than comma delimiters. Those are the only other functions I can find just now. (You could also save them using fprintf to write the file, but that tends to be more difficult to write code for, and may not be as easy for other functions to read.)

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!