フィルターのクリア

Delete line of file based on number in first column

1 回表示 (過去 30 日間)
Henrik Larsen
Henrik Larsen 2016 年 9 月 5 日
コメント済み: arvind ramasamy 2018 年 7 月 11 日
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

採用された回答

Azzi Abdelmalek
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 件のコメント
Henrik Larsen
Henrik Larsen 2016 年 9 月 8 日
I don't know if I need to make a new question, anyway here goes:
I can't make it work if forexample i just make an empty line like this:
8 Job Operator Date Time Instrument
8 15899-2016 THP/KVE 16-08-11 08:13:09 1626136
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
This will just give me an out of bound error, I have tried to work it out myself but I just can get it to work.
Any suggestions?
arvind ramasamy
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 ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by