How to write text line to line ?
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Arif
 el 25 de Mzo. de 2024
  
    
    
    
    
    Comentada: Stephen23
      
      
 el 25 de Mzo. de 2024
            Hi, please help me to write text-file contain characters that are arranged in line to line like this picture :

here is my code to build the text :
clear
clc
VariantModel = compose('%c', 'C':'G')         
for k = 1:numel(VariantModel)
    writefile(VariantModel{k})
end
files = dir('*.s2k');
files(:).name
function  writefile(C)
    fido = fopen("Model"+C+".s2k",'wt');
    spacing = '    '
    line1='File D:\\MAGISTER\\KULIAH\\TESIS\\Model%c.s2k was saved on m/d/yy at h:mm:ss'
    line2='TABLE:  "ACTIVE DEGREES OF FREEDOM"'
    line3='   UX=Yes   UY=No   UZ=Yes   RX=No   RY=Yes   RZ=No'
    line4='TABLE:  "ANALYSIS OPTIONS"'
    line5='   Solver=Advanced   SolverProc=Auto   Force32Bit=No   StiffCase=None   GeomMod=None   HingeOpt="In Elements"   NumAThreads=0   MaxFileSize=0   NumDThreads=0   NumRThreads=0   UseMMFiles="Program Determined"   AllowDiff=No'
    combine = append(line1,spacing,line2,spacing,line3,spacing,line4,spacing,line5)
    fprintf(fido,combine,C);
    fclose(fido);
end
but it give the result like this :

Respuesta aceptada
  Yash
      
 el 25 de Mzo. de 2024
        
      Editada: Yash
      
 el 25 de Mzo. de 2024
  
      Hi Arif,
Instead of using "spacing", you should use the "newline" character ('\n'). Once you use this, your data will be arranged as desired. Here is the updated code:
clear
clc
VariantModel = compose('%c', 'C':'G') ;        
for k = 1:numel(VariantModel)
    writefile(VariantModel{k});
end
function  writefile(C)
    fido = fopen("Model"+C+".s2k",'wt');
    % spacing = '    '
    newline = '\n';
    line1='File D:\\MAGISTER\\KULIAH\\TESIS\\Model%c.s2k was saved on m/d/yy at h:mm:ss';
    line2='TABLE:  "ACTIVE DEGREES OF FREEDOM"';
    line3='   UX=Yes   UY=No   UZ=Yes   RX=No   RY=Yes   RZ=No';
    line4='TABLE:  "ANALYSIS OPTIONS"';
    line5='   Solver=Advanced   SolverProc=Auto   Force32Bit=No   StiffCase=None   GeomMod=None   HingeOpt="In Elements"   NumAThreads=0   MaxFileSize=0   NumDThreads=0   NumRThreads=0   UseMMFiles="Program Determined"   AllowDiff=No';
    % combine = append(line1,spacing,line2,spacing,line3,spacing,line4,spacing,line5)
    combine = append(line1,newline,line2,newline,line3,newline,line4,newline,line5);
    fprintf(fido,combine,C);
    fclose(fido);
end
Hope this helps!
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Language Support en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


