using command readcell to read specific structure

15 Ansichten (letzte 30 Tage)
Hi, I have discovered that I have some issues when combining the output data that were saved in a text file. I tried to use readmatrix but some data are lost.
For example, I have attached three text files that contains cell data with columns and rows. The number of columns have a constant value of 70, and the number of rows it may vary from each file. When I have created a foor loop to read all the data and combine them in a global matrix, I realized that some files files are read as cell arrays and they are not separated like the others and create an issue when combining them. I was trying to spit the files and create some conditions for those cases but some data is loose and the number of columns changes. I would appreciate the help.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Aug. 2024
Verschoben: Walter Roberson am 13 Aug. 2024
A = readcell('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1752014/19510131163900.txt')
A = 1x70 cell array
Columns 1 through 11 {'1951 01 31 16:...'} {[-12.2100]} {[-76.9300]} {[50]} {[214.3877]} {[6]} {'ML'} {'1951 01 31 16:...'} {[6.0140]} {'Mw'} {[-12.2100]} Columns 12 through 26 {[-76.9300]} {[50]} {[214.3877]} {[-999]} {[-999]} {[-999]} {[1]} {[6]} {'ML'} {[-999]} {[1]} {[-999]} {[-999]} {[-999]} {[-999]} Columns 27 through 40 {[-999]} {[-999]} {[-999]} {[-999]} {[-999]} {[-999]} {[-999]} {[-999]} {[22.3738]} {[320.2590]} {[76.7727]} {[-55.5219]} {[1]} {[11]} Columns 41 through 53 {[-1]} {[-1]} {[-1]} {'CISMID'} {'CIS'} {'PRQ'} {[-12.0700]} {[-77.0399]} {[121.3048]} {[19.6264]} {[53.7140]} {[53.6274]} {[47.9744]} Columns 54 through 65 {[47.8612]} {[14.5720]} {[-10.0749]} {[44.6251]} {[11.6490]} {[12.1181]} {[178.8920]} {[54.4850]} {[2.7344]} {[2.7345]} {[2.7137]} {[11.7981]} Columns 66 through 70 {[2.5671]} {[2.4574]} {[3.3366]} {[111.6214]} {[25.8605]}
B = readcell('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1752019/19661017214200.txt', 'Delimiter', '\t')
B = 1x70 cell array
Columns 1 through 11 {[17-Oct-1966 21:42:00]} {[-10.6650]} {[-78.2280]} {[39]} {[-219]} {[8.1000]} {'Mw'} {[17-Oct-1966 21:41:59]} {[8.1000]} {'Mw'} {[-10.6845]} Columns 12 through 26 {[-78.3380]} {[38.7000]} {[-219]} {[335]} {[12]} {[90]} {[1]} {[8.1000]} {'mw'} {[2]} {[0]} {[21]} {[-999]} {[-999]} {[-999]} Columns 27 through 41 {[-999]} {[-999]} {[335]} {[12]} {[90]} {[155]} {[78]} {[90]} {[22.4900]} {[328.9427]} {[75.3516]} {[-43.0296]} {[1]} {[5]} {[-1]} Columns 42 through 53 {[-1]} {[-1]} {'ISC,USGS'} {'CIS'} {'PRQ'} {[-12.0700]} {[-77.0399]} {[121.3048]} {[209.1797]} {[212.7295]} {[212.7917]} {[<missing>]} Columns 54 through 64 {[<missing>]} {[103.6439]} {[118.2896]} {[19.1026]} {[208.6012]} {[128.3247]} {[328.9427]} {[22.4900]} {[<missing>]} {[<missing>]} {[41.0362]} Columns 65 through 70 {[40.4827]} {[7.3536]} {[73.1680]} {[46.2567]} {[5.7127e-14]} {[1.4282e-14]}
C = readcell('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1752024/19700531202328.txt', 'Delimiter', '\t')
C = 1x70 cell array
Columns 1 through 11 {'1970 05 31 20:...'} {[-9.1830]} {[-78.7370]} {[45]} {[-79.6951]} {[7.9000]} {'Mw'} {[31-May-1970 20:23:30]} {[7.9000]} {'Mw'} {[-9.2245]} Columns 12 through 25 {[-78.7920]} {[51.7000]} {[-79.6951]} {[160]} {[37]} {[-90]} {[1]} {[7.9000]} {'mw'} {[1]} {[1]} {[21]} {[<missing>]} {[<missing>]} Columns 26 through 38 {[<missing>]} {[<missing>]} {[<missing>]} {[340]} {[53]} {[-90]} {[160]} {[37]} {[-90]} {[19.2159]} {[329.9212]} {[73.4738]} {[-59.0754]} Columns 39 through 51 {[1]} {[5]} {[-1]} {[-1]} {[-1]} {'ISC,USGS'} {'CIS'} {'PRQ'} {[-12.0700]} {[-77.0399]} {[121.3048]} {[369.8139]} {[373.4102]} Columns 52 through 63 {[373.4381]} {[324.7374]} {[324.7135]} {[317.6109]} {[99.0766]} {[26.8536]} {[96.2152]} {[68.8943]} {[160]} {[37]} {[23.1587]} {[23.1605]} Columns 64 through 70 {[23.8214]} {[14.5348]} {[7.0771]} {[30.1916]} {[19.9641]} {[0]} {[0]}
  2 Kommentare
Jorge Luis Paredes Estacio
Jorge Luis Paredes Estacio am 14 Aug. 2024
Thank you for your reply. I still have the issue and you can see in B and C. I do not know why?. Thank you
A=readcell([[path_SD,'/'],Files_SD(1).name])
A =
1×70 cell array
Columns 1 through 7
{'1951 01 31 16:3…'} {[-12.2100]} {[-76.9300]} {[50]} {[214.3877]} {[6]} {'ML'}
Columns 8 through 15
{'1951 01 31 16:3…'} {[6.0140]} {'Mw'} {[-12.2100]} {[-76.9300]} {[50]} {[214.3877]} {[-999]}
Columns 16 through 26
{[-999]} {[-999]} {[1]} {[6]} {'ML'} {[-999]} {[1]} {[-999]} {[-999]} {[-999]} {[-999]}
Columns 27 through 35
{[-999]} {[-999]} {[-999]} {[-999]} {[-999]} {[-999]} {[-999]} {[-999]} {[22.3738]}
Columns 36 through 45
{[320.2590]} {[76.7727]} {[-55.5219]} {[1]} {[11]} {[-1]} {[-1]} {[-1]} {'CISMID'} {'CIS'}
Columns 46 through 53
{'PRQ'} {[-12.0700]} {[-77.0399]} {[121.3048]} {[19.6264]} {[53.7140]} {[53.6274]} {[47.9744]}
Columns 54 through 61
{[47.8612]} {[14.5720]} {[-10.0749]} {[44.6251]} {[11.6490]} {[12.1181]} {[178.8920]} {[54.4850]}
Columns 62 through 69
{[2.7344]} {[2.7345]} {[2.7137]} {[11.7981]} {[2.5671]} {[2.4574]} {[3.3366]} {[111.6214]}
Column 70
{[25.8605]}
B=readcell([[path_SD,'/'],Files_SD(2).name])
B =
1×2 cell array
{'1966-10-17 21:42:00→-10.665→-78.228→39→-219→8.1…'} {'USGS→CIS→PRQ→-12.07→-77.0399→121.3048→209.1797→…'}
C=readcell([[path_SD,'/'],Files_SD(3).name])
C =
1×2 cell array
{'1970 05 31 20:23:28→-9.183→-78.737→45→-79.6951→7…'} {'USGS→CIS→PRQ→-12.07→-77.0399→121.3048→369.8139→…'}
Jorge Luis Paredes Estacio
Jorge Luis Paredes Estacio am 14 Aug. 2024
Thank you very much. My mistake. I have not seen the last part " 'Delimiter', '\t'". So, I added a condition based on the length. Have a nive daym :).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by