Hello, I hope you can assist me. I’ve been collecting a substantial amount of data, resulting in a data.txt file containing around 35,000 lines. For example:
09:38:25.184 <FL111 Po0 t1198 t2195 PLTI153 FM250 Er0 HB2 B0 t3225 VS150 I0 AT0 TC32
09:38:25.284 <FL111 Po0 t1198 t2197 PLTI153 FM250 Er0 HB2 B0 t3225 VS150 I0 AT0 TC42
09:38:25.389 <FL111 Po0 t1198 t2198 PLTI153 FM250 Er0 HB2 B0 t3225 VS150 I0 AT0 TC52
09:38:25.473 <FL111 Po0 t1198 t2197 PLTI153 FM250 **Er** HB2 B0 t3225 VS150 I0 AT0 TC62
09:38:25.583 <FL111 Po0 t1198 t2195 PLTI153 FM250 Er0 HB2 B0 t3225 VS150 I0 AT0 TC72
09:38:25.677 <FL111 Po0 t1197 t2198 PLTI153 FM250 Er0 HB2 B0 t3225 VS150 I0 AT0 TC82
In one of the lines, specifically the one with Er (which lacks a number), I encounter an issue.
I’m attempting to read this data.txt file in Scilab 2023.1 and extract all the values into a matrix for subsequent post-processing.
Here’s the script I’m using:
Steps = csvRead('data.txt', ascii(9), [], "string"); // Read data into a matrix
i = 1;
for j = 1:u // Loop through the CoolTerm Matrix Measurement
if "FL" == part(Steps(j,v), 1:2) then // Filter messages starting with FL
Time(i,:) = msscanf(Steps(j,1), "%d:%d:%d.%d"); // Read Time String into double
Serial(i,:) = msscanf(Steps(j,v), "FL%d Po%d t1%d t2%d PLTI%d FM%d Er%d HB%d B%d t3%d VS%d I%d AT%d TC%d"); // Move String Values into a Double Matrix
i = i + 1;
end
end
type or paste code here
However, due to the missing number at Er, I’m encountering the following error message: “Submatrix incorrectly defined.” Is there a way to skip this line and proceed to the next one? Could using a “Try…Catch…End” approach be beneficial?
I’ve also experimented with the following code:
filename = 'data.txt';
file = mopen(filename, 'r');
Steps = mgetl(file, -1); // Read the file line by line
variable_name = "DATA"; // Store all measurements in one matrix or struct
i = 1;
for cnt = 1:size(Steps,'*') // Load only consistent data
try
param(cnt,:) = tokens(Steps(cnt))';
end
// Additional conditions could be added here
end
However, this approach takes a significant amount of time as Scilab examines each line thoroughly. Is there a more efficient way to achieve this?