Filter löschen
Filter löschen

how to import repeating block data of text file in MATLAB?

3 Ansichten (letzte 30 Tage)
Lei am 25 Jul. 2011
i have a few datasets need to be processed, but i dont know how to import them to the matlab since I am a biginner of MATLAB. The data looks like this:
NANO0840 2011-07-15 12:11:29 12.1v INL 39.0% 40.0 DegC
50% RxM 250 TxX 20 TxY 20 #T 1
Tx Delay 1.5 Antenna Delay 2 Alias IN
Robust None Window ZONGE
1 NanoTEM A/D 16-bit S/N 64 Passed 1.00000
Front Panel S/N 56, Cal S/N 172, Temp 40.0, Humidity 39.0, EPROM BD387 0840
NANO0840 2011-07-15 12:13:14 12.1v INL 39.0% 40.0 DegC
Tx 1 Rx 1 N OUT
64 Hz 128 Cyc Tx Curr 3 4.819u 1u 1.606u
1 Hz 1 222.94u 80.23u 24.82 000O 62.23u 0.00 0
Wn Mag 1 Rho 1
0.319u 1.5825 674.98
1.925u 0.4227 81.201
3.531u 0.1736 53.453
5.137u 90.065m 44.321
6.743u 53.728m 39.743
8.350u 34.973m 37.061
10.73u 21.064m 34.221
13.95u 11.979m 32.190
17.16u 7.5831m 30.896
21.14u 4.8296m 29.500
25.97u 3.1097m 28.075
32.28u 1.9126m 27.009
41.08u 1.1106m 25.968
51.49u 659.11u 25.235
64.24u 376.08u 25.367
80.23u 222.94u 24.824
100.9u 110.88u 26.994
128.0u 66.548u 25.512
161.6u 30.614u 29.035
203.1u 12.955u 35.197
255.0u 11.043u 26.791
321.0u 10.813u 18.504
404.9u 13.808u 10.678
508.7u -0.9989u 42.045
639.4u 4.7662u 10.133
805.4u 5.4792u 6.2862
1.014m 2.5061u 7.2169
1.276m 2.7276u 4.6476
1.607m 0.0791u 33.511
2.022m 1.8926u 2.7528
2.547m 2.7681u 1.4547
except of block 126, the other blocks are the same.each block i am able to use the textscan to import one block of data, but have no idea how to import all of these data in one time. Anybody would like to give a hand?
Thanks a lot.
  2 Kommentare
Walter Roberson
Walter Roberson am 25 Jul. 2011
Are there always exactly 31 lines of Wn / Mag / Rho data?
Lei am 25 Jul. 2011
yes, Each block has 6 headerlines, 3 colums and 31 rows except the very first block. The first block has 9 header lines without numerics. and for all of the blocks,there's one space.
I used the fid=fopen('filename');
C=textscan(fid,'%*d %*d %*d %*d %*s %f %*d %f %f %f %f %f','headerlines',9);
a=cell2mat(C) to get one block data.
My big problem is that i dont know which function should i use or do i need to write a loop and how. Thank you so mych

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Jul. 2011
fid = fopen('filename');
textscan(fid, '', 1, 'headerlines', 10); %skip entire block
C = {};
while true
thisblock = textscan('%f%*c%f%*c%f', 31, 'headerlines', 6, 'CollectOutput', 1);
if all(cellfun(@isempty,thisblock)); end; break; %end of file
C{end+1} = thisblock{1};
Warning: this ignores the 'u' and 'm' suffixes. You have not given any indication of how you want to handle those.
This code will produce one cell array in C per block read in.
This code makes no attempt to read anything out of the first block.
This code makes no attempt to read the block number or any other header.

Weitere Antworten (0)


Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by