issue regarding reading .txt file with comments
Mostrar comentarios más antiguos
Hello, I am trying to load a 'txt' file and plot it. It has just 2 columns and multiple rows. I also have few rows which have comments which i can not remove. But when i load the file and plot it. it just plot the data till the row which has the 1st comment. After that it is not acknowledging or reflecting the data. What can be done for this? Please help me out. I am using 2018 version Thanks in advance.
3 comentarios
Walter Roberson
el 1 de Ag. de 2018
How are the comments indicated in the text?
KSSV
el 1 de Ag. de 2018
A snippet of file or attaching the file will help us to help you.
Akshat Shrivastava
el 1 de Ag. de 2018
Respuesta aceptada
Más respuestas (1)
More robust:
opt = {'CommentStyle','#', 'CollectOutput',true};
[fid,msg] = fopen('yourfile.txt','rt');
assert(fid>=3,msg)
C = textscan(fid, '%f%f', opt{:});
fclose(fid);
M = C{1};
Or use dlmread.
6 comentarios
Akshat Shrivastava
el 2 de Ag. de 2018
Akshat Shrivastava
el 3 de Ag. de 2018
@Akshat Shrivastava: please upload your data file. I cannot load a screenshot as data.
Please show the code that you used. If you do not show the code you used than I have to guess or imagine what you are doing. Guessing is not a very accurate way to debug code!
Akshat Shrivastava
el 3 de Ag. de 2018
Akshat Shrivastava: please upload your data file. I cannot load a screenshot as data.
Possibly you just need to add 'MultipleDelimsAsOne' to the options cell array, but without your actual data file this is impossible for me to test.
Or you might be able to trivially use dlmread. This would be easy to check if I had your data file.
Walter Roberson
el 3 de Ag. de 2018
In particular we need to verify whether the file is tab delimited or simple space delimited or is fixed width fields.
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!