Best way to import and use data from a text file in Matlab that is numeric and has dates?

1 visualización (últimos 30 días)
I'm new to MatLab and I'm really confused by how many different ways I can import data into MatLab.
I have a tab delimited (or seperated) text file that has 5 columns and thousands of rows. I am not sure the best way to import and use this data in MatLab. My end goal is to be able to make a plot of a span of 10 years (column 3) of the streamflow (column 4). So I only need to use to data found in columns 3 and 4. Here is how my text file looks (this is only a small part of it).
USGS 040871475 2005-09-30 0.52 A
USGS 040871475 2005-10-01 0.37 A
USGS 040871475 2005-10-02 0.31 A
USGS 040871475 2005-10-03 0.32 A
USGS 040871475 2005-10-04 0.31 A
USGS 040871475 2005-10-05 0.29 A
I've tried fopen / textscan, but I get a cell array and I don't know how to alter the information inside the cell array. I tried converting the cell array to a normal array by cell2struct but that isn't working. Here is what I've tried and know it's wrong...
fid = fopen('MKEDischargeData3.txt');
mat = textscan(fid, '%s %d %s %f %c');
newmat = [mat(:, 3) mat(:, 4)];
colHeadings = {'time' 'streamflow'};
structArray = cell2struct(newmat, colHeadings, 2)
Also, hopefully I could have it be in a format that I would be able to use/alter the dates for the plot. I am not sure how to do that either so if anyone knows that would be great.

Respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by