How to extract two type of data from text without losing indexing?
Show older comments
I have .txt data from sensors in the following format:

I wanted to import x, y data (as highlighted in green) and the parametric data (highlighted in blue).
I was able to exract separately using the following code
Imp= importdata('Test.txt') ;
Imp(1,:) = [];
TF = contains(Imp,"0 0"); % for extracting the parametric data
S = Imp(TF); %This option only stores the above mentioned data, thus losing the indexing.
I made empty columns for the parameters
cols = length(S);
Para1 = zeros(cols,1); %Parameter 1
Para2 = zeros(cols,1); %Parameter 2
Para3 = zeros(cols,1); %Parameter 3
...
Then I ran the loop to put the specific values into those arrays
for i = 1:cols
sample=S(i);
sample = extractAfter(sample,"*");
sample = extractAfter(sample,":");
sample = extractAfter(sample,":");
values = string(sample);
values = str2num(values);
Para1(i) = values(3);
Para2(i) = values(4);
Para3(i) = values(5);
end
I used the same method to find the x and y values. But it gave me 2 tables with no data on index numbers. This way I lose the indexing of the original data. Because later I want to relate these specific parameters to the corresponding x,y coordinates.
My idea is to somehow make the GP# rows equal to zero instead of [], so that later I can trace back the index numbers. I cannot achieve that. In the end result I want to have a table which has the data in this form (table made in excel).

Any help in this will be much appreciated. I am also attaching the text.txt file.
~thanks.
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!