Process .dat file, plot, scale, and put back into similar format
4 views (last 30 days)
Have looked at fopen, textscan, importdata, running into issues, could use support...
looking to open, ignore the headers, then import this file's tabular data, read from left to right, then down: It's all Y axis data, with x starting from 0 in increments of 0.005 sec, plot the time history, resample and recale at 0.02 seconds and output the tabular x,y data and generate a similar .dat file placed in 8 columns without the x values.
Having issues with which is the best option for file importing, delimiting and data type issues and have gone thru all the examples and can't pin it down.
Any help or insight appreciated.
Star Strider on 27 May 2023
It would help to have the file rather than an image.
I would do something like this:
fidi = fopen('Hled.dat','rt');
C = textscan(fidi, repmat('%f',1,8), 'HeaderLines',16, 'Delimiter',' ', 'CollectOutput',1);
EarthQuake = cell2mat(C);
The readmatrix function with the same 'HeaderLines' information would also work.
More Answers (3)
Walter Roberson on 27 May 2023
Your code says to scan the file for 8 floating point numbers with commas between them with a delimiter of tab. But your file contains columns of 8 floating point numbers with no commas
importdata expects a file name rather than a file identifier with the exception that the first parameter may be the special name '-pastespecial' instead of a file name.
Steven Lord on 30 May 2023
You may want to interactively experiment with the various options for importing your data in the Import Tool. You can specify the range of data to import, control whether MATLAB should interpret the file as delimited or fixed-width, and specify how you want the data to be imported into MATLAB (table, vectors, cell array, etc.)
Once you've changed the settings so the data looks the way you want, you can import the data (if you only have this one file to read in) or generate MATLAB code to import the data (if you have multiple files formatted the same way and you want to reuse the commands to import each of the files.)