extracting only number from text file
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ImageAnalyst
le 20 Avr 2020
Commenté : Akira Agata
le 22 Avr 2020
Hi,
I have a large text file which has data in below format
frame_count: 1, frame_type: p, mv_dst: (8, 8), mv_src: (8, 8), mv_type: f, motion: (0, 0, 4), mb: (16, 16)
frame_count: 1, frame_type: p, mv_dst: (24, 8), mv_src: (24, 8), mv_type: f, motion: (0, 0, 4), mb: (16, 16)
and so on.
I want to extract the value of mv_dst,mv_src and first two numbers of value motion and store in a matrix in below format
frame_count: 1, frame_type: p, mv_dst: (8, 8), mv_src: (8, 8), mv_type: f, motion: (0, 0, 4), mb: (16, 16)
Matrix should have value like this
first matrix with value from mv_dst(8,8) and first value from motion motion: (0, 0, 4) [ 0 in this case]
x_vec y_vec motion
8 8 0
second matrix with value from mv_src(8,8) and second value from motion :motion: (0, 0, 4) [ 0 in this case]
x_vec y_vec motion
8 8 0
0 commentaires
Réponse acceptée
Akira Agata
le 21 Avr 2020
How about the following?
% Read the original text file
c = readcell('data.txt','Delimiter','\n');
% Extract coordinates from each line
cData = regexp(c,'\d+,\s+\d+(,\s+\d+)*','match');
cData = vertcat(cData{:});
% Arrange the numbers
mv_dst = str2double(split(cData(:,1),','));
mv_src = str2double(split(cData(:,2),','));
motion = str2double(split(cData(:,3),','));
% 1st and 2nd matrix
T1 = array2table([mv_dst,motion(:,1)],'VariableNames',{'x_vec','y_vec','motion'});
T2 = array2table([mv_src,motion(:,2)],'VariableNames',{'x_vec','y_vec','motion'});
5 commentaires
Akira Agata
le 22 Avr 2020
Hi Arya-san,
Thank you for sharing the file. But, unfortunately, I could not unzip the file. Could you upload the file (original file or newly zipped file) again?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!