Delete line of file based on number in first column
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Azzi Abdelmalek
2016-9-5
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 个评论
arvind ramasamy
2018-7-11
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!