How to take a data form text file to put it in another file?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Yamina chbak
 el 3 de Feb. de 2022
  
    
    
    
    
    Comentada: Yamina chbak
 el 4 de Feb. de 2022
            Hi,
I have a text file called File.1.node which contain such as:
45 12 7 1                       ( first line )
 1 2 1 1
 2 3 2 1
 3 4 5 1
.....
% File.1.node is complete       (last line )
I want to take  the data from File.1.node  without first line and last line, to put it in another file named Node.dat.
But How i write a code for this problem? 
Thanks in advance.
0 comentarios
Respuesta aceptada
  Star Strider
      
      
 el 3 de Feb. de 2022
        Try this — 
fidi = fopen('File.1.node','rt');
F1c = textscan(fidi, '%f%f%f%f', 'HeaderLines',1, 'CollectOutput',1);
fclose(fidi);
F1 = cell2mat(F1c);
dlmwrite(F1, 'Node.dat')
.
4 comentarios
  Star Strider
      
      
 el 4 de Feb. de 2022
				@Stephen — Thank you.  
The other answer was originally accepted, and I deleted my original (correct) answer as the result.  I got an e-mail requesting  that I re-post it so that it could be accepted.  I did it from memory, and did not remember the correct argument order to dlmwrite (correct in my original answer) because I rarely used it even before writematrix appeared.  (My original answer used readmatrix and writematrix, however A Achbak does not have access to them.  The dlmwrite call appeared in a subsequent Comment.)  
Más respuestas (1)
  David Hill
      
      
 el 3 de Feb. de 2022
        See what readmatrix gives you
m=readmatrix('File.1.node.txt');
m(1,:)=[];
writematrix(m,'Node.dat');
If you do not attach the file, we cannot test.
5 comentarios
  David Hill
      
      
 el 3 de Feb. de 2022
				
      Editada: David Hill
      
      
 el 3 de Feb. de 2022
  
			What about this?
m=dlmread('File.1.node',' ',[1 0 592 3]);
Ver también
Categorías
				Más información sobre Text Files en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



