Effacer les filtres
Effacer les filtres

.txt file edit

2 vues (au cours des 30 derniers jours)
Ayush Sharma
Ayush Sharma le 12 Sep 2017
Commenté : Rik le 12 Sep 2017
Respected all,
I have a text file with some set of data which is being imported.
A snapshot of the same is shown as follows.
Now, I need to load this text file in MATLAB, and shall start from the second line (as I do not need the first one).
ie:<Date><Time><BN Count><Error Message Content><Error Title><Category> ,where href = ""</a> are the delimiters *which shoul dhave been removed once the text file is loaded in the matlab directory using the "load data.txt" command)
Now, I need to append the second line in a new text file.
For this, how do I need to modify this answer .?? or is there a better way to do so.
I am not sure whether this is will work or not, as this includes appended data in matrix form.
Now,as one may observe the snapshot, the first value corresponds to the date. I need to copy only those row data afterward which are corresponding to a specific date (ex: 01-01-2006), for this, maybe the MATLAB needs to move one row to another, check the first column data , compare it with the user defined value of date and then append the data to the new text file if the date matches with the specified date. For this matching, will the following set of commands do my job?
(for data.txt, the row no. (n) will start from 1 to the end of the file)
variable=data(n,1);
if (variable == "01-01-2006")
% append the data as to be done above
Now, once the code performs this operation, the new text file is to be exported in an excel sheet.
Please help me with this complete operation.
Thanks
Regards
  1 commentaire
Rik
Rik le 12 Sep 2017
I suggest you read the documentation for load. You will find that it doesn't load your text file (or it might by accident). Some relevant functions for loading a text file: fopen, fread, textscan and fclose.
To compare two dates, I would suggest converting your text to a datenum. Also, remember that double quotes will generate a string array, while single quotes produce a char. Both have their use, but in general input for functions should be char. For comparing two chars, you should use strcmp to avoid Matlab trying to compare element-wise, which may result in an error for unequal sized string inputs.
I your goal is an output of an excel file, why bother with a text file intermediary? Just go for xlswrite (which, despite the name, is also capable of writing xlsx files).

Connectez-vous pour commenter.

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by