how to get data from a .txt file.I need numerical data only after 'Init seq' to perform calculations in matlab and create a .txt file with new data same as the source file.
------------------ Header -------------------------------------
TestDescription
DateTime 06.02.2013;11:50:17
SensorType COMBO1.5 SENSOR
FrameType OFFFRAME
CPOL 0
CPHA 0
Sensor 2
SensorRS485
SensorArmingPinX
SensorArmingPinY
SensorPullResistor
AD 1;2;3;4
Digital
SensorVcc 3.30 V
BurstRate 2000 Hz
MOSICount_Burst 20
SPIRate 40000 Hz
SCLK 8000000 Hz
ToolVersion
FPGAVersion SC 0.10
DeviceName USB <-> SPICE SN: 00009
ProjectFilename Project_Combo1.5.spi-cfg
CommandFilename Bosch_COMBO_1_5_SPI_Commands_and_Replies.h
CommandFileRevision 1.22
CRCTableFilename Bosch_COMBO_1_5_SPI_CRC_Table.c
CRCTableFileRevision 1.4
HW-State;Time[ms];MOSI[hex];MISO2[hex];MISO2-State;AIn1[mV];AIn2[mV];AIn3[mV];AIn4[mV];
------------------ Init Sequence ------------------------------
80;0.000;402B01E8;FFFFFFFF;00; 10;122;1993;1994;
80;0.025;802B00FB;FFFFFFFF;05; 11;123;1995;1996;
80;0.050;806000FE;FFFFFFFF;05; 11;122;1995;1996;
80;0.075;803E00E2;FFFFFFFF;05; 10;121;1993;1994;
80;0.100;803E00E2;FFFFFFFF;00; 11;124;1996;1998;
80;0.125;80500091;FFFFFFFF;00; 10;121;1993;1995;
80;0.150;80510078;FFFFFFFF;05; 10;122;1993;1995;
80;0.175;8052006C;FFFFFFFF;05; 12;123;1995;1997;
80;0.200;80530085;FFFFFFFF;05; 10;122;1993;1994;
80;0.225;80540044;FFFFFFFF;05; 12;123;1995;1997;
80;0.250;805500AD;FFFFFFFF;05; 10;122;1995;1996;
80;0.275;805600B9;FFFFFFFF;05; 10;121;1992;1993;
80;0.300;80570050;FFFFFFFF;05; 11;123;1996;1998;
80;0.325;80580014;FFFFFFFF;05; 10;122;1993;1995;
80;0.350;805900FD;FFFFFFFF;05; 10;122;1994;1995;
80;0.375;805A00E9;FFFFFFFF;05; 12;123;1996;1997;
80;0.400;40290115;FFFFFFFF;05; 10;121;1993;1994;
80;0.425;20000002;FFFFFFFF;05; 11;123;1996;1997;
80;0.450;600000F3;FFFFFFFF;05; 10;122;1995;1995;
80;0.475;A00000CF;FFFFFFFF;05; 10;122;1993;1994;
80;0.500;802F002E;FFFFFFFF;05; 11;123;1996;1998;
80;0.525;803100A6;FFFFFFFF;05; 10;122;1993;1995;
80;0.550;8033005B;FFFFFFFF;05; 11;123;1995;1996;
80;0.575;40290115;FFFFFFFF;05; 11;122;1995;1996;
80;0.600;20000002;FFFFFFFF;05; 10;122;1993;1993;
80;0.625;600000F3;FFFFFFFF;05; 11;123;1996;1998;
80;0.650;A00000CF;FFFFFFFF;05; 10;122;1993;1995;
80;0.675;802F002E;FFFFFFFF;05; 10;122;1993;1994;
80;0.700;803100A6;FFFFFFFF;05; 12;123;1996;1997;
80;0.725;8033005B;FFFFFFFF;05; 10;122;1993;1994;
80;0.750;40290115;FFFFFFFF;05; 10;123;1995;1997;
80;0.775;20000002;FFFFFFFF;05; 11;122;1994;1996;
80;0.800;600000F3;FFFFFFFF;05; 10;121;1992;1994;
80;0.825;A00000CF;FFFFFFFF;05; 12;124;1997;1998;
80;0.850;802F002E;FFFFFFFF;05; 10;122;1993;1995;
80;0.875;803100A6;FFFFFFFF;05; 10;122;1994;1995;

 Akzeptierte Antwort

Charles David
Charles David am 14 Feb. 2013

0 Stimmen

use textscan command and since you do not need the initail lines use the 'HeaderLines' option(in that you can specify how many lines u want to skip) use this: first open the file with fopen assume file identifier used is fid then, C=textscan(fid,'%d%f%s%s%d%d%d%d%d','Delimeter',';','HeaderLines','30');

2 Kommentare

shanmukh
shanmukh am 14 Feb. 2013
i tried the code,
fid = fopen('test.txt');
C=textscan(fid,'%d%f%s%s%d%d%d%d%d','Delimeter',';','HeaderLines','30');
i get an error 'Header lines must be integer-valued'
The header lines values needs to be a numeric instead of a string:
textscan(fid,... 'HeaderLines',30)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

the cyclist
the cyclist am 14 Feb. 2013
Bearbeitet: the cyclist am 14 Feb. 2013

0 Stimmen

If you have a relatively new version of MATLAB (2012b or newer, I think), there is an "Import Data" tool in Home tab of the command window. Via a GUI, you can select the data to import. MATLAB will also generate code for you to do this programmatically.
Saif Awwad
Saif Awwad am 8 Mai 2015

0 Stimmen

Do you need to achieve this exclusively by using MATLAB? This is a relatively easy task if using SHELL or PERL languages.

1 Kommentar

Walter Roberson
Walter Roberson am 8 Mai 2015
Stephen, I removed your flag. The Answer discusses the possibility of using an additional tool to preprocess the data, which is a fair response. In particular, calling perl is built-in to MATLAB, see here so suggesting using a MATLAB invocation of Perl is definitely in-bounds for the Answers forum.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by