Copy dedicated values from a text file and store them inside Excel sheet

hello. I have several text files which have data stored in them in following manner:
1.1 ECU Identification (Ford Escape Initial)
PDU Parameter Value Unit
[7E8]
06 00 OBDMIDs OBDmonitorIDsSupported$01_$1F
ExhaustGasSensorMonitorBank1Sensor1 supported
ExhaustGasSensorMonitorBank1Sensor2 supported
06 01 Monitor ID ExhaustGasSensorMonitorBank1Sensor1
testValue 0.009 s
minimumTestLimit 0.000 s
maximumTestLimit 0.400 s
Test ID 0x87
Monitor ID ExhaustGasSensorMonitorBank1Sensor1
testValue 0.020 s
minimumTestLimit 0.000 s
maximumTestLimit 0.400 s
Test ID 0x88
06 02 Monitor ID ExhaustGasSensorMonitorBank1Sensor2
testValue -7876 mV/s
minimumTestLimit -30000 mV/s
maximumTestLimit 0 mV/s
Test ID 0x85
Monitor ID ExhaustGasSensorMonitorBank1Sensor2
testValue 1.889 s
minimumTestLimit 0.000 s
maximumTestLimit 6.000 s
Test ID 0x86
06 20 OBDMIDs OBDmonitorIDsSupported$21_$3F
CatalystMonitorBank1 supported
VVTMonitorBank1 supported
EVAPmonitorCapOff not supported
EVAPmonitor_0_090 supported
EVAPmonitor_0_040 supported
EVAPmonitor_0_020 supported
PurgeFlowMonitor supported
and so on...
I need to copy and store the values given in the parameter and value columns against PDU values in an Excel sheet. I am fairly new to MATLAB programming and I know xlsread can be used in this Situation but I dont know how. Any Kind of help in this regard is greatly appreciated. Thank you.

8 Comments

xlsread() cannot be used for that file. The file is not a spreadsheet and it is not comma separated values.
Is it possible that in the original file, the columns are separated by tabs?
here is the text file that i am using, and no i dont think that the columns are separated by Tabs.
let us take a small portion of that for illustration:
06 00 OBDMIDs OBDmonitorIDsSupported$01_$1F
ExhaustGasSensorMonitorBank1Sensor1 supported
ExhaustGasSensorMonitorBank1Sensor2 supported
06 01 Monitor ID ExhaustGasSensorMonitorBank1Sensor1
testValue 0.009 s
minimumTestLimit 0.000 s
maximumTestLimit 0.400 s
Test ID 0x87
Monitor ID ExhaustGasSensorMonitorBank1Sensor1
testValue 0.020 s
minimumTestLimit 0.000 s
maximumTestLimit 0.400 s
Test ID 0x88
What would you want the output to be for that portion?
in ideal condition it would be very complicated, well to me it seems very complicated but for right now, i would like to copy this exact format right in to the excel spreadsheet.
Do you want each line to become one cell? Or do you want it separated out, so for example,
{'06', '00', 'OBDMIDs', 'OBDmonitorIDsSupported$01_$1F';
[], [], 'ExhaustGasSensorMonitorBank1Sensor1', 'supported';
...
Do you need the numeric values to be detected and converted into numeric form? For example, 0.009 stored instead of '0.009' ? How about the '0x87', should that be converted to numeric 135 ?
importing this text file into a cell Array and then onto Excel spreadsheet. Thats what i have been trying to do till now but unsuccessful in doing so.
actually no. 0X87 should remain 0X87. And the above format that you posted seems about right, except that it should be 06 00 instead of '06' '00' and so on.

Sign in to comment.

Answers (1)

Are you sure you want the 06 00 to come out as numeric? Those are hex values not decimal. Did you possibly mean that you wanted '06 00' instead of '06' '00'?
I have attached a function to read the contents of one of these files. The code converts the hex PDU numbers to decimal because you seemed to request that. You also implicitly approved that for example '0.009' should become 0.009 so I convert the 4th column to numeric whenever that works out and leave it as text when it does not.
The output of the code is a cell array that you can then xlswrite().
Example:
odx = readodx('Test1.txt');
xlswrite('Test1.xlsx', odx);
For consistency, I convert all empty fields to the empty numeric array, [], rather than to empty strings, ''
Empty lines are skipped.
The column numbers and widths are hard-coded, the P and L vectors in the code. The string fields are permitted to contain blanks, which would make it difficult for the program to figure out where the columns started.
The starting line is not hard-coded, but the code currently does expect to see the 'PDU' line and for there to be the dashed line below it.

1 Comment

Thank you so much for the detailed answer. With some tweaks here and there, i managed to run it successfully. Thank you once again.

Sign in to comment.

Tags

Asked:

on 1 Jun 2016

Commented:

on 6 Jun 2016

Community Treasure Hunt

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

Start Hunting!