Take number data from Global Ionospheric Scintillation Model *.txt and save to *xlsx in batch

Version 1.0.0.0 (248 KB) by Tian
This code originaly from Walter Roberson when i ask in mathworks.
52 Downloads
Updated 25 Oct 2017

View License

This code originaly from Walter Roberson when i ask in mathworks. His profile is https://www.mathworks.com/matlabcentral/profile/authors/434782-walter-roberson
I share this code so people included me can easily get this code when needed.
If you have any question feel free to ask me or you can ask walter roberson directly.

This code will not work properly if the numbers might be in exponential format. For example if there is an entry 3.12345E-7 then the 'E' would be detected and the entire line would be thrown away. The code as posted is only for the case where there are no exponents and no complex-number indicators.

Explanation about the code is below:
The code reads the file in as one string. Then it uses the regular expression replacement routine to change certain patterns of code.

In particular, it first detects the pattern of a line that might start and end with anything, but in the middle of the line has at least one alphabetic character in ['a':'z', 'A':'Z']. When it finds such lines, it changes the entire line to '' which is the empty line.

regexprep then takes the lines that are left and changes all whitespace at the beginning of lines to the empty string. This has two benefits: it changes lines that are all-blank to be empty; and it gets rid of the leading spaces on the other lines.

With those two text patterns altered, the text is then split into lines, giving temp as the output.

Then all of the empty lines in temp are deleted: these are the lines that were empty in the original file, together with the liens that were changed to be empty because at least one letter was found on the line.

With the empty lines deleted, what is left in temp is just the lines containing the numbers. If all you needed was a text file of those, that could be easily written without converting to number.

The lines of text containing numbers is then split at every run of spaces. This gives a cell array in which there is one entry per line and those entries are a cell array with one entry per column. The vertcat() call arranges all of those columns on top of each other, still as text. Then the str2double() call converts the strings representing numbers into numbers. There are other ways that the strings representing the numbers could have been converted to numeric, but this is one of the safest ways.

Cite As

Tian (2024). Take number data from Global Ionospheric Scintillation Model *.txt and save to *xlsx in batch (https://www.mathworks.com/matlabcentral/fileexchange/64840-take-number-data-from-global-ionospheric-scintillation-model-txt-and-save-to-xlsx-in-batch), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Logical in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0