importing data and plotting
21 views (last 30 days)
Show older comments
SHERIN ANN ABRAHAM
on 17 Nov 2020
Answered: Tyann Hardyn
on 26 Jun 2021
How can I load this txt file with some text at starting and numericals.I want to plot H,D,Z,F values aginst time see attached file plse
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/416478/image.png)
3 Comments
Mario Malic
on 17 Nov 2020
https://www.mathworks.com/help/matlab/ref/importtool.html I would not know if 2007 has it.
Accepted Answer
Mathieu NOE
on 17 Nov 2020
hello
impordata or readtable will do the trick
example with impordata :
importdata('abg20000212dminn.txt')
ans =
1466×1 cell array
{' Format IAGA-2002 |'}
{' Source of Data Indian Institute of Geomagnetism |'}
{' Station Name Alibag |'}
{' IAGA CODE ABG |'}
{' Geodetic Latitude 18.620 |'}
{' Geodetic Longitude 72.870 |'}
{' Elevation 0 |'}
{' Reported HDZF |'}
{' Sensor Orientation HDZF |'}
{' Digital Sampling 5.0 seconds |'}
{' Data Interval Type Average 1-Minute (00:30-01:29) |'}
{' Data Type Definitive |'}
{' # D-conversion factor 110800 |'}
{' # K9-limit |'}
{' # This data file was converted from INTERMAGNET CD-ROM |'}
{' # Format binary data. |'}
{' # A complete set is available on the INTERMAGNET CD-ROM. |'}
{' # Go to www.intermagnet.org for details on obtaining this product. |'}
{' # CONDITIONS OF USE: These data are for scientific/academic use |'}
{' # For any other applications see the 'Conditions of Use' published |'}
{' # on the INTERMAGNET web site - www.intermagnet.org |'}
{' # D conversion factor is a fixed value used to allow |'}
{' # Declination to be converted from minutes of arc to equivalent |'}
{' # nanoteslas. Set to H/3438*10000 where H is the annual mean |'}
{' # value of horizontal intensity. |'}
{'DATE TIME DOY ABGH ABGD ABGZ ABGF |'}
{'2000-02-12 00:00:00.000 043 99999.00 99999.00 99999.00 99999.00'}
{'2000-02-12 00:01:00.000 043 38132.70 -21.20 18442.20 99999.00'}
{'2000-02-12 00:02:00.000 043 38131.90 -21.20 18443.20 99999.00'}
{'2000-02-12 00:03:00.000 043 38132.20 -21.10 18443.90 99999.00'}
{'2000-02-12 00:04:00.000 043 38132.90 -21.10 18444.60 99999.00'}
{'2000-02-12 00:05:00.000 043 38132.00 -21.00 18445.70 99999.00'}
{'2000-02-12 00:06:00.000 043 38129.50 -20.80 18447.20 99999.00'}
{'2000-02-12 00:07:00.000 043 38129.00 -20.80 18448.00 99999.00'}
{'2000-02-12 00:08:00.000 043 38129.20 -20.80 18448.00 99999.00'}
.....
example with readtable
T = readtable(filename,'VariableNamingRule' ,'preserve');
M = table2cell(T)
M =
1454×12 cell array
Columns 1 through 6
{[NaT ]} {[NaN ]} {[NaN]} {[ 110800]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[NaT ]} {[NaN ]} {[NaN]} {[ NaN]} {[ NaN]} {[ NaN]}
{[2000-02-12]} {[00:00:00]} {[ 43]} {[ 99999]} {[ 99999]} {[ 99999]}
{[2000-02-12]} {[00:01:00]} {[ 43]} {[3.8133e+04]} {[-21.2000]} {[1.8442e+04]}
{[2000-02-12]} {[00:02:00]} {[ 43]} {[3.8132e+04]} {[-21.2000]} {[1.8443e+04]}
{[2000-02-12]} {[00:03:00]} {[ 43]} {[3.8132e+04]} {[-21.1000]} {[1.8444e+04]}
{[2000-02-12]} {[00:04:00]} {[ 43]} {[3.8133e+04]} {[-21.1000]} {[1.8445e+04]}
{[2000-02-12]} {[00:05:00]} {[ 43]} {[ 38132]} {[ -21]} {[1.8446e+04]}
............
4 Comments
Mathieu NOE
on 27 May 2021
suggestion :
T = readtable('abg20000212dminn.txt','VariableNamingRule' ,'preserve',"NumHeaderLines",25);
[m,n] = size(T);
% data collected each minute on 24 hours = 1440 values
time = 1:m;
% plot H,D,Z,F values aginst time
H = T.ABGH;
D = T.ABGD;
Z = T.ABGZ;
F = T.ABGF;
% plot all data together
plot(time,[H D Z F],'linewidth',2);
legend('H','D','Z','F');
More Answers (2)
Peter Perkins
on 19 Nov 2020
In a more recent version of MATLAB, I would suggest to not use importdata. It's old and gives you a result that is hard to work with. I'd suggest readtimetable, or readtable in less recent versions.
In R2007? If you have the Statistics Toolbox, you could use the dataset function to read from a file.
There are very inexpensive versions of MATLAB for home use, I'd suggest you consider that. After all, your time is worth something, and a new version will save you time. Reading and plotting these data is two lines of code in a recent version.
0 Comments
Tyann Hardyn
on 26 Jun 2021
Try this :
filename = 'path of abg20000212dminn.txt';
startRow = 14;
formatSpec = '%10{yyyy-MM-dd}D%13s%4f%13f%10f%10f%f%[^\n\r]';
fileID = fopen(namafile,'r');
textscan(fileID, '%[^\n\r]', startRow-1, 'WhiteSpace', '', 'ReturnOnError', false, 'EndOfLine', '\r\n');
dataArray = textscan(fileID, formatSpec, 'Delimiter', '', 'WhiteSpace', '', 'TextType', 'string', 'EmptyValue', NaN, 'ReturnOnError', false);
DATE = dataArray{:,1};
TIME = dataArray{:,2};
DOY = dataArray{:,3};
ABGX = dataArray{:,4};
ABGY = dataArray{:,5};
ABGZ = dataArray{:,6};
ABGF = dataArray{:,7};
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!