Reading and plotting data

1 view (last 30 days)
Jacob Allen
Jacob Allen on 21 Sep 2022
Commented: Eric Sofen on 21 Sep 2022
I've listed out the things that will help me get started with this data:
1. Read the Seismic data (use fopen, textscan, fclose functions)
only need up to the first 5 columns (ignore the rest using “%*[^\n]”)
2. Remove ‘z’ & ‘t’ contained in time column (use strrep function)
3. Convert dates into serial numbers (use datenum function)
4. Create scatter plot
Use datetick function to see dates on plot
I've searched which functions do the best for each job but I'm having touble implementing them.
The data file is attached
  1 Comment
Eric Sofen
Eric Sofen on 21 Sep 2022
Note that you don't need to use datetick to display dates on a scatter plot any more. You can directly plot datetime or durations in most chart types.

Sign in to comment.

Answers (1)

Chunru
Chunru on 21 Sep 2022
x = readtable("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1131005/Lab3.csv")
x = 205×22 table
time latitude longitude depth mag magType nst gap dmin rms net id updated place type horizontalError depthError magError magNst status locationSource magSource ____________________________ ________ _________ _____ ___ _______ ___ ___ ____ ____ ______ ______________ ____________________________ _________________________________ ______________ _______________ __________ ________ ______ ____________ ______________ _________ {'2016-11-07T01:44:24.500Z'} 35.991 -96.803 4.43 5 {'mww'} NaN 52 NaN 0.25 {'us'} {'us100075y8'} {'2022-05-03T19:46:41.269Z'} {'3 km W of Cushing, Oklahoma' } {'earthquake'} 0.5 1.8 NaN NaN {'reviewed'} {'tul'} {'us' } {'2015-10-10T22:03:05.300Z'} 35.986 -96.803 3.274 4.3 {'mwr'} NaN 54 NaN 0.6 {'us'} {'us10003mqq'} {'2020-08-25T22:29:47.958Z'} {'3 km W of Cushing, Oklahoma' } {'earthquake'} 2.5 5.2 0.039 62 {'reviewed'} {'tul'} {'us' } {'2014-10-10T13:51:21.000Z'} 35.947 -96.759 5 4.2 {'mwr'} NaN 63 NaN 0.45 {'us'} {'usb000skq4'} {'2022-08-07T02:23:59.839Z'} {'4 km S of Cushing, Oklahoma' } {'earthquake'} 3.4 6.8 0.037 72 {'reviewed'} {'tul'} {'us' } {'2015-09-18T12:35:16.600Z'} 35.993 -96.8 0.208 4.1 {'mwr'} NaN 54 NaN 0.82 {'us'} {'us20003l6t'} {'2020-03-20T00:31:38.221Z'} {'3 km WNW of Cushing, Oklahoma'} {'earthquake'} 2.5 6 0.034 82 {'reviewed'} {'tul'} {'us' } {'2014-10-07T16:51:13.100Z'} 35.947 -96.764 5.28 4 {'mwr'} NaN 81 NaN 0.61 {'us'} {'usb000sjk0'} {'2022-08-07T02:13:20.861Z'} {'4 km S of Cushing, Oklahoma' } {'earthquake'} 3.9 5.8 0.033 90 {'reviewed'} {'tul'} {'us' } {'2015-09-25T01:16:37.700Z'} 35.987 -96.787 2.893 4 {'mwr'} NaN 76 NaN 0.73 {'us'} {'us20003nwb'} {'2020-08-25T22:34:26.769Z'} {'1 km W of Cushing, Oklahoma' } {'earthquake'} 1.9 4.8 0.037 72 {'reviewed'} {'tul'} {'us' } {'2015-09-16T02:30:01.900Z'} 35.978 -96.795 4.019 3.7 {'mwr'} NaN 56 NaN 0.77 {'us'} {'us20003jvi'} {'2020-03-20T00:30:58.848Z'} {'2 km WSW of Cushing, Oklahoma'} {'earthquake'} 2.7 6.5 0.048 41 {'reviewed'} {'tul'} {'us' } {'2015-12-18T02:03:25.100Z'} 35.987 -96.799 5.563 3.7 {'ml' } NaN 50 NaN 0.57 {'us'} {'us1000481y'} {'2020-03-20T00:50:27.237Z'} {'2 km W of Cushing, Oklahoma' } {'earthquake'} 1.8 0.7 NaN NaN {'reviewed'} {'tul'} {'tul'} {'2015-09-27T21:59:43.310Z'} 35.986 -96.797 5.1 3.6 {'ml' } NaN NaN NaN 0.49 {'us'} {'us20003pjy'} {'2015-12-28T23:08:45.040Z'} {'2 km W of Cushing, Oklahoma' } {'earthquake'} 2.7 4 NaN NaN {'reviewed'} {'tul'} {'tul'} {'2016-11-24T16:34:06.600Z'} 35.993 -96.798 5.707 3.6 {'ml' } NaN 54 NaN 0.3 {'us'} {'us10007c4b'} {'2017-02-15T23:21:39.040Z'} {'2 km WNW of Cushing, Oklahoma'} {'earthquake'} 0.8 1.5 NaN NaN {'reviewed'} {'tul'} {'tul'} {'2015-04-12T22:55:56.100Z'} 35.949 -96.775 4.45 3.5 {'ml' } NaN 79 NaN 0.4 {'us'} {'us20002606'} {'2020-03-20T00:05:51.647Z'} {'4 km S of Cushing, Oklahoma' } {'earthquake'} 2 2.7 NaN NaN {'reviewed'} {'tul'} {'tul'} {'2015-11-08T19:59:06.000Z'} 35.98 -96.819 4.192 3.5 {'ml' } NaN 51 NaN 0.49 {'us'} {'us10003vst'} {'2020-03-20T00:39:04.467Z'} {'4 km W of Cushing, Oklahoma' } {'earthquake'} 2.3 7 NaN NaN {'reviewed'} {'tul'} {'tul'} {'2015-10-31T06:14:04.900Z'} 35.987 -96.798 4.66 3.5 {'ml' } NaN 55 NaN 0.7 {'us'} {'us2000411m'} {'2022-08-01T14:51:16.836Z'} {'2 km W of Cushing, Oklahoma' } {'earthquake'} 2 5 NaN NaN {'reviewed'} {'tul'} {'tul'} {'2016-11-22T09:55:33.300Z'} 36.007 -96.769 4.44 3.5 {'mwr'} NaN 59 NaN 0.45 {'us'} {'us10007bdl'} {'2020-03-20T01:36:23.183Z'} {'2 km N of Cushing, Oklahoma' } {'earthquake'} 1.3 2 NaN 21 {'reviewed'} {'tul'} {'slm'} {'2015-09-01T09:43:50.000Z'} 35.949 -96.784 3.892 3.4 {'ml' } NaN 47 NaN 0.65 {'us'} {'us20003fc5'} {'2022-08-01T02:57:27.342Z'} {'4 km SSW of Cushing, Oklahoma'} {'earthquake'} 2 4.6 NaN NaN {'reviewed'} {'tul'} {'tul'} {'2015-09-02T14:01:26.240Z'} 35.949 -96.781 3.7 3.3 {'mwr'} NaN NaN NaN 0.49 {'us'} {'us20003fqc'} {'2022-08-01T03:16:56.785Z'} {'4 km SSW of Cushing, Oklahoma'} {'earthquake'} 2.1 6.9 NaN 9 {'reviewed'} {'tul'} {'slm'}
x.('datetime') = datetime(x.time, "InputFormat", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
x = 205×23 table
time latitude longitude depth mag magType nst gap dmin rms net id updated place type horizontalError depthError magError magNst status locationSource magSource datetime ____________________________ ________ _________ _____ ___ _______ ___ ___ ____ ____ ______ ______________ ____________________________ _________________________________ ______________ _______________ __________ ________ ______ ____________ ______________ _________ ____________________ {'2016-11-07T01:44:24.500Z'} 35.991 -96.803 4.43 5 {'mww'} NaN 52 NaN 0.25 {'us'} {'us100075y8'} {'2022-05-03T19:46:41.269Z'} {'3 km W of Cushing, Oklahoma' } {'earthquake'} 0.5 1.8 NaN NaN {'reviewed'} {'tul'} {'us' } 07-Nov-2016 01:44:24 {'2015-10-10T22:03:05.300Z'} 35.986 -96.803 3.274 4.3 {'mwr'} NaN 54 NaN 0.6 {'us'} {'us10003mqq'} {'2020-08-25T22:29:47.958Z'} {'3 km W of Cushing, Oklahoma' } {'earthquake'} 2.5 5.2 0.039 62 {'reviewed'} {'tul'} {'us' } 10-Oct-2015 22:03:05 {'2014-10-10T13:51:21.000Z'} 35.947 -96.759 5 4.2 {'mwr'} NaN 63 NaN 0.45 {'us'} {'usb000skq4'} {'2022-08-07T02:23:59.839Z'} {'4 km S of Cushing, Oklahoma' } {'earthquake'} 3.4 6.8 0.037 72 {'reviewed'} {'tul'} {'us' } 10-Oct-2014 13:51:21 {'2015-09-18T12:35:16.600Z'} 35.993 -96.8 0.208 4.1 {'mwr'} NaN 54 NaN 0.82 {'us'} {'us20003l6t'} {'2020-03-20T00:31:38.221Z'} {'3 km WNW of Cushing, Oklahoma'} {'earthquake'} 2.5 6 0.034 82 {'reviewed'} {'tul'} {'us' } 18-Sep-2015 12:35:16 {'2014-10-07T16:51:13.100Z'} 35.947 -96.764 5.28 4 {'mwr'} NaN 81 NaN 0.61 {'us'} {'usb000sjk0'} {'2022-08-07T02:13:20.861Z'} {'4 km S of Cushing, Oklahoma' } {'earthquake'} 3.9 5.8 0.033 90 {'reviewed'} {'tul'} {'us' } 07-Oct-2014 16:51:13 {'2015-09-25T01:16:37.700Z'} 35.987 -96.787 2.893 4 {'mwr'} NaN 76 NaN 0.73 {'us'} {'us20003nwb'} {'2020-08-25T22:34:26.769Z'} {'1 km W of Cushing, Oklahoma' } {'earthquake'} 1.9 4.8 0.037 72 {'reviewed'} {'tul'} {'us' } 25-Sep-2015 01:16:37 {'2015-09-16T02:30:01.900Z'} 35.978 -96.795 4.019 3.7 {'mwr'} NaN 56 NaN 0.77 {'us'} {'us20003jvi'} {'2020-03-20T00:30:58.848Z'} {'2 km WSW of Cushing, Oklahoma'} {'earthquake'} 2.7 6.5 0.048 41 {'reviewed'} {'tul'} {'us' } 16-Sep-2015 02:30:01 {'2015-12-18T02:03:25.100Z'} 35.987 -96.799 5.563 3.7 {'ml' } NaN 50 NaN 0.57 {'us'} {'us1000481y'} {'2020-03-20T00:50:27.237Z'} {'2 km W of Cushing, Oklahoma' } {'earthquake'} 1.8 0.7 NaN NaN {'reviewed'} {'tul'} {'tul'} 18-Dec-2015 02:03:25 {'2015-09-27T21:59:43.310Z'} 35.986 -96.797 5.1 3.6 {'ml' } NaN NaN NaN 0.49 {'us'} {'us20003pjy'} {'2015-12-28T23:08:45.040Z'} {'2 km W of Cushing, Oklahoma' } {'earthquake'} 2.7 4 NaN NaN {'reviewed'} {'tul'} {'tul'} 27-Sep-2015 21:59:43 {'2016-11-24T16:34:06.600Z'} 35.993 -96.798 5.707 3.6 {'ml' } NaN 54 NaN 0.3 {'us'} {'us10007c4b'} {'2017-02-15T23:21:39.040Z'} {'2 km WNW of Cushing, Oklahoma'} {'earthquake'} 0.8 1.5 NaN NaN {'reviewed'} {'tul'} {'tul'} 24-Nov-2016 16:34:06 {'2015-04-12T22:55:56.100Z'} 35.949 -96.775 4.45 3.5 {'ml' } NaN 79 NaN 0.4 {'us'} {'us20002606'} {'2020-03-20T00:05:51.647Z'} {'4 km S of Cushing, Oklahoma' } {'earthquake'} 2 2.7 NaN NaN {'reviewed'} {'tul'} {'tul'} 12-Apr-2015 22:55:56 {'2015-11-08T19:59:06.000Z'} 35.98 -96.819 4.192 3.5 {'ml' } NaN 51 NaN 0.49 {'us'} {'us10003vst'} {'2020-03-20T00:39:04.467Z'} {'4 km W of Cushing, Oklahoma' } {'earthquake'} 2.3 7 NaN NaN {'reviewed'} {'tul'} {'tul'} 08-Nov-2015 19:59:06 {'2015-10-31T06:14:04.900Z'} 35.987 -96.798 4.66 3.5 {'ml' } NaN 55 NaN 0.7 {'us'} {'us2000411m'} {'2022-08-01T14:51:16.836Z'} {'2 km W of Cushing, Oklahoma' } {'earthquake'} 2 5 NaN NaN {'reviewed'} {'tul'} {'tul'} 31-Oct-2015 06:14:04 {'2016-11-22T09:55:33.300Z'} 36.007 -96.769 4.44 3.5 {'mwr'} NaN 59 NaN 0.45 {'us'} {'us10007bdl'} {'2020-03-20T01:36:23.183Z'} {'2 km N of Cushing, Oklahoma' } {'earthquake'} 1.3 2 NaN 21 {'reviewed'} {'tul'} {'slm'} 22-Nov-2016 09:55:33 {'2015-09-01T09:43:50.000Z'} 35.949 -96.784 3.892 3.4 {'ml' } NaN 47 NaN 0.65 {'us'} {'us20003fc5'} {'2022-08-01T02:57:27.342Z'} {'4 km SSW of Cushing, Oklahoma'} {'earthquake'} 2 4.6 NaN NaN {'reviewed'} {'tul'} {'tul'} 01-Sep-2015 09:43:50 {'2015-09-02T14:01:26.240Z'} 35.949 -96.781 3.7 3.3 {'mwr'} NaN NaN NaN 0.49 {'us'} {'us20003fqc'} {'2022-08-01T03:16:56.785Z'} {'4 km SSW of Cushing, Oklahoma'} {'earthquake'} 2.1 6.9 NaN 9 {'reviewed'} {'tul'} {'slm'} 02-Sep-2015 14:01:26
x = x(:, [end 2:5]) % select data
x = 205×5 table
datetime latitude longitude depth mag ____________________ ________ _________ _____ ___ 07-Nov-2016 01:44:24 35.991 -96.803 4.43 5 10-Oct-2015 22:03:05 35.986 -96.803 3.274 4.3 10-Oct-2014 13:51:21 35.947 -96.759 5 4.2 18-Sep-2015 12:35:16 35.993 -96.8 0.208 4.1 07-Oct-2014 16:51:13 35.947 -96.764 5.28 4 25-Sep-2015 01:16:37 35.987 -96.787 2.893 4 16-Sep-2015 02:30:01 35.978 -96.795 4.019 3.7 18-Dec-2015 02:03:25 35.987 -96.799 5.563 3.7 27-Sep-2015 21:59:43 35.986 -96.797 5.1 3.6 24-Nov-2016 16:34:06 35.993 -96.798 5.707 3.6 12-Apr-2015 22:55:56 35.949 -96.775 4.45 3.5 08-Nov-2015 19:59:06 35.98 -96.819 4.192 3.5 31-Oct-2015 06:14:04 35.987 -96.798 4.66 3.5 22-Nov-2016 09:55:33 36.007 -96.769 4.44 3.5 01-Sep-2015 09:43:50 35.949 -96.784 3.892 3.4 02-Sep-2015 14:01:26 35.949 -96.781 3.7 3.3
% try do the rest yourself

Categories

Find more on Dates and Time in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!