creating an array from a txt file
Mostrar comentarios más antiguos
sorry if this is a silly question, but I have just started to use matlab.
I am trying to create an array using the txt file 'ifng.txt' however I want to remove the first row as it is just headers, this is what I have so far
function output = IFNG2016
fid= fopen('ifng.txt','r');
A = textscan(fid, '%f', 'HeaderLines', 1)
however it just prints
A= [0x1 Double]
any assistance would be appreciated.
Thanks
6 comentarios
Thorsten
el 28 de Jun. de 2016
It would be helpful to upload the file ifng.txt.
Andreas Donauer
el 28 de Jun. de 2016
Editada: Andreas Donauer
el 28 de Jun. de 2016
One of many posibilities:
% open the file
fid = fopen('ifng.txt'); % could check if fid is nonempty here
% read first line
tline = fgets(fid);
index = 0;
% if char (not end of file), keep reading
while ischar(tline)
index = index+1;
txt{index} = tline(1:end-1); % store line in a cell-array-of-strings
tline = fgets(fid);
end
% close file
fclose(fid);
% re-format starting from line 2
script = sprintf('%s',txt{2:end});
% replace line feeds (windows)
script(script==13) = sprintf('\n');
% finally, print what you've been reading in command line:
fprintf(script);
Andreas Donauer
el 28 de Jun. de 2016
Have you tried what I posted? If this works for you, please check the question solved.
Star Strider
el 28 de Jun. de 2016
@Andreas Donauer —
Post your Comment here as an Answer.
C Mck
el 28 de Jun. de 2016
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing 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!