MATLAB Answers

0

How to read the given type of data from text file as an input to my further matlab code

Asked by Nemalikanti Akhila on 28 Oct 2017
Latest activity Answered by Cedric Wannaz
on 28 Oct 2017
1 1:123 2:1.316440 3:1.516003 4:5.605905 5:5.346760 6:0.013233 7:0.010729 8:0.091743 9:0.050768 10:3808.067871 11:702.992493 12:7533.133301 13:1390.499268 14:971.098511 15:1894.978027 16:114.965019 17:45.018257 18:0.635224 19:0.095226 20:0.063398 21:0.061210 22:0.038319 23:0.018285 24:0.011113 25:0.007736 26:0.004864 27:0.004220 28:0.003273 29:0.002699 30:0.002553 31:0.002323 32:0.002108 33:0.002036 34:0.001792 35:0.001553 36:0.001250 37:0.001317 38:0.001084 39:0.000818 40:0.000624 41:0.000586 42:0.000529 43:0.000426 44:0.000359 45:0.000446 46:0.000268 47:0.000221 48:0.000154 49:0.000217 50:0.000193 51:0.000163 52:0.000165 53:0.000210 54:0.000114 55:0.000130 56:0.000055 57:0.000013 58:0.733037 59:0.133122 60:0.041263 61:0.019699 62:0.010962 63:0.006927 64:0.004525 65:0.003128 66:0.002314 67:0.001762 68:0.001361 69:0.001065 70:0.000914 71:0.000777 72:0.000667 73:0.000565 74:0.000520 75:0.000467 76:0.000469 77:0.000486 78:0.000417 79:0.000427 80:0.000349 81:0.000258 82:0.000262 83:0.000344 84:0.000168 85:0.000163 86:0.001058 90:0.020584 91:0.185038 92:0.148316 93:0.047098 94:0.169797 95:0.061318 96:0.002200 97:0.010440 98:0.004463 100:0.010558 101:0.002067 102:0.338970 103:0.470364 104:0.189997 105:0.018296 106:0.126517 107:0.047620 108:0.045863 109:0.184865 110:0.095976 111:0.015295 112:0.056323 113:0.024587 115:0.037647 116:0.006015 117:0.160327 118:0.251688 119:0.176144 123:0.006356 219:0.002119 276:0.002119 296:0.341102 448:0.099576 491:0.069915 572:0.141949 573:0.103814 601:0.002119 623:0.050847 726:0.038136 762:0.036017 816:0.036017 871:0.016949 924:0.008475 959:0.036017 1002:0.006356 1016:0.008475 1048:0.002119 4124:0.422333825949 4125:0.663917631952 1 1:124 2:0.966079 3:0.546420 4:4.046537 5:3.190973 6:0.008338 7:0.011490 8:0.075504 9:0.065841 10:3466.266113 11:904.122925 12:7580.040039 13:1391.858643 14:724.249573 15:1722.364502 16:110.605591 17:47.206207 18:0.630358 19:0.136130
this whole data is my one line in txt file . how can I read m entire file?

  2 Comments

how can we read your question? Please format using {} Code button and if this is the sample of your text file, attach it using the paperclip icon.
The irregularity in following the same formatting for fields at the beginning means will have to read as string variables and parse each individual entry or use regexp...I'm not guru with regular expressions but undoubtedly one can write one that will work.
I don't think even the new datetime class will handle that level of precision in the fractional seconds field, however. It's unlikely that is meaningful anyway one would suspect...

Sign in to comment.

2 Answers

Answer by Jan
on 28 Oct 2017

There is a trivial answer: fileread reads the entire file. But I guess that you want to split and interpret the data, but you did not mention any details unfortunately. So what is the wanted output?
s = fileread(FileName);
c = strsplit(s, ' ');
Now most of the substrings have the format "a:b", but there are two "1" also. I cannot guess, what you want as output then, but if should not be hard to obtain it - after it is defined clearly.

  0 Comments

Sign in to comment.


Answer by Cedric Wannaz
on 28 Oct 2017

Is the following working?
data = reshape(sscanf(strrep(fileread('MyData.txt'), ':', ' '), '%f'), 310, []).' ;

  0 Comments

Sign in to comment.