Delete line of file based on number in first column
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Henrik Larsen
le 5 Sep 2016
Commenté : arvind ramasamy
le 11 Juil 2018
I'm trying to delete lines in a file based on a number in the first "column" of the file. The file(s) looks something like:
8 Job Operator Date Time Instrument
8 15899-2016 THP/KVE 16-08-11 08:13:09 1626136
8
8 PT Code y X Z
6 CKOTE1 250 137827.548 98704.895 32.880
6 CKOTE2 250 137828.245 98707.396 32.880
6 CKOTE3 250 137830.581 98711.226 32.880
8 CKOTE4 250 137833.055 98713.677 32.879
So my questions is how i tell matlab to skip lines containing the char "8" in the first column, so I get the remaining data:
6 CKOTE1 250 137827.548 98704.895 32.880
6 CKOTE2 250 137828.245 98707.396 32.880
6 CKOTE3 250 137830.581 98711.226 32.880
Thanks
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 5 Sep 2016
fid=fopen('file.txt');
l1=strtrim(fgetl(fid));
out={};
while ischar(l1)
l2=strtrim(l1);
if l2(1)~='8'
out{end+1,1}=l1;
end
l1=fgetl(fid);
end
out
2 commentaires
arvind ramasamy
le 11 Juil 2018
I make a serial communication with an arduino and get the data of accelerometer mag and gyro values my data comes in as a string. 's' is the object i created for serial communication
data =fscanf(s,%s) % gives me the data from the arduino
i want my vector size to be 500. so when I run it in for loop
for i= 1:50
data =fscanf(s,'%s');
end
my output is: data = initializationsuccesful!
data = ax:123ay:23az:1234gx:23gy:50gz:43mx:23my:123mz:234
and goes on.
I use,
A_x(:,i) = str2num(data(:,4:8))
to get my vector. but since 'initializationsuccessful!' is not a number i am unable to form my vector. so how can I do it ???? this is my question
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur MATLAB Support Package for Arduino Hardware 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!