Hello everybody,
I have a trouble in reading the text file with some attached data. Every value is a 5-digital integer. So I used textscan to get the value:
fid = fopen('text.txt','r');priformat1='%5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d';% priformat1='%5s %5s %5s %5s %5s %5s %5s %5s %5s %5s %5s %5s %5s %5s'; I also try
st = fgetl(fid);if strfind(st,'NODES') st=fgetl(fid); F = cell2mat(textscan(fid,priformat1)); F = double(F)else error('no NODES found !');end%
st = fgetl(fid);if ~isempty(findstr(st,'ELEMT')) G = cell2mat(textscan(fid,priformat1)); G = abs(double(G));else error('Oops...*.PRI file problem - no ELEMT found !');endfclose(fid);
However the value I obtained is not correct when the value is attached. For example: in the fourth line of NODES after 9518: 9825101076….is not recognized well by textscan. sometimes the data like ' 10110010', if I used 5%d as parameters, the output will be 10110, 10. But I need is 101,10010 I tried a lot input parameters such as whitespace, %5c, and textread…. I was not managed to read such text.
Could you help me for this problem? thank you very much.
———–the following is the txt file——————
NODES
NODES -3 666 1595 1693 1911 2154 2434 2464 2578 2845 3276 3420 3752 3837 -3 4324 4329 4624 4924 5194 5498 5715 5737 5832 6048 6083 6261 6579 -3 6647 6673 6772 6806 7085 7292 7597 7694 7803 8111 8135 8329 8640 -3 8809 8891 9205 9518 98251017610195102671039810508106541082411062 -311116112111133511355115981162411702118431193912121121641219512406 -312446125081251212526127271277012964129691308813135132901370913910 -4 666 1595 1693 1911 2154 2434 2464 2578 2845 3276 3420 3752 3837 -4 4324 4329 4624 4924 5194 5498 5715 5737 5832 6048 6083 6261 6579 -4 6647 6673 6772 6806 7085 7292 7597 7694 7803 8111 8135 8329 8640ELEMT 1 462 468 687 943 947 1135 1138 1141 1144 1351 1591 1596 1598 1 2350 2356 2522 2711 2715 2860 2863 2866 3020 3197 3202 3204 4786 1 4792 5403 6107 6111 6630 6633 6636 6639 6642 6645 6648 6651 6654 1 6657 6660 7229 7889 7894 7896 9728 97341009010497105011078510788 110791107941079710800111341151711522115241218612188121901219212240 112242122441236812370123721237412376123781238012382123841238612388 2 462 468 687 943 947 1135 1138 1141 1144 1351 1591 1596 1598 2 2350 2356 2522 2711 2715 2860 2863 2866 3020 3197 3202 3204 4786REACT--------------------the end of txt file-------(p.s. the number of line is not fixed)
————–The matrix I need is:——
NODES=[-3 666 1595 1693 1911 2154 2434 2464 2578 2845 3276 3420 3752 3837-3 4324 4329 4624 4924 5194 5498 5715 5737 5832 6048 6083 6261 6579-3 6647 6673 6772 6806 7085 7292 7597 7694 7803 8111 8135 8329 8640-3 8809 8891 9205 9518 9825 10176 10195 10267 10398 10508 10654 10824 11062-3 11116 11211 11335 11355 11598 11624 11702 11843 11939 12121 12164 12195 12406-3 12446 12508 12512 12526 12727 12770 12964 12969 13088 13135 13290 13709 13910-4 666 1595 1693 1911 2154 2434 2464 2578 2845 3276 3420 3752 3837-4 4324 4329 4624 4924 5194 5498 5715 5737 5832 6048 6083 6261 6579-4 6647 6673 6772 6806 7085 7292 7597 7694 7803 8111 8135 8329 8640 ] and ELEMT=[1 462 468 687 943 947 1135 1138 1141 1144 1351 1591 1596 15981 2350 2356 2522 2711 2715 2860 2863 2866 3020 3197 3202 3204 47861 4792 5403 6107 6111 6630 6633 6636 6639 6642 6645 6648 6651 66541 6657 6660 7229 7889 7894 7896 9728 9734 10090 10497 10501 10785 107881 10791 10794 10797 10800 11134 11517 11522 11524 12186 12188 12190 12192 122401 12242 12244 12368 12370 12372 12374 12376 12378 12380 12382 12384 12386 123882 462 468 687 943 947 1135 1138 1141 1144 1351 1591 1596 15982 2350 2356 2522 2711 2715 2860 2863 2866 3020 3197 3202 3204 4786 ] REACT=[]
Best Answer