Info

This question is closed. Reopen it to edit or answer.

How to remove some charterers from the set of values

1 view (last 30 days)
Hi there
I am trying to remove
#00:GEOPAK-WIN Scanning
#02:Contour 1
#04:XY(Z)
#05:Opn
#06:MM
#07:0.00000
#12
I tried to read the file and removed lines but it is not working , any suggestion ?
Thanks a lot for your help in advance
  1 Comment
James Marashi
James Marashi on 30 May 2015
Thanks for every one respond and apology for not attaching the file . #00:GEOPAK-WIN Scanning #02:Contour 1 #04:XY(Z) #05:Opn #06:MM #07:0.00000 #12 are the parts which i don't need . I want to read the text file and remove these parts and save it in a new file . I am new to Matlab so i don't know how to solve this problem .

Answers (2)

Star Strider
Star Strider on 24 May 2015
Edited: Star Strider on 24 May 2015
You did not say how you tried to read the file or what the file structure is, but if those lines are header lines (at the beginning of the file), you can (probably) read the file with textscan, using 'HeaderLines',7 to skip those lines.
EDIT — I edited your original post so that the lines you want to eliminate were the list as you entered them, with each line beginning with #. For some reason, you removed my edit. For the record, they appear in the body text as:
#00:GEOPAK-WIN Scanning
#02:Contour 1
#04:XY(Z)
#05:Opn
#06:MM
#07:0.00000
#12
and not as a single line. I assume the list are the same way they appear in your file, rather than all of them on one line.
EDIT 2 — ‘I tried to read the file and removed lines but it is not working , any suggestion ?’
One suggestion: Tell us what is ‘not working’!
We have neither your code nor file, so we’re quite limited in the help we can provide.
What is your code doing that you don’t want it to do, or what is it not doing that you do?
  1 Comment
Star Strider
Star Strider on 30 May 2015
This works:
fidi = fopen('James Marashi tosend.txt','rt');
k1 = 0;
while ~feof(fidi)
k1 = k1 + 1;
D{k1} = textscan(fidi, '%*4c %f %f %f %f %f %f', 'HeaderLines',6, 'Delimiter','\t', 'CollectOutput',1, 'EndOfLine','\r\n');
end
celldisp(D) % Display Results
The celldisp call displays what the code has read. It is there to demonstrate that it works, and isn’t necessary for the code, so delete it or comment it out when you are happy that it is doing what you want.

Image Analyst
Image Analyst on 24 May 2015
You forgot to attach the file. So about all I can guess at is to use fgetl() and see if the first character is a # symbol
textline = fgetl(fid);
if textline(1) == '#'
% Do or not do something.
end
Please explain in detail what "remove" means to you. Do you want to create another file that has all the lines except the ones starting with # removed?

Tags

Community Treasure Hunt

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

Start Hunting!