Borrar filtros
Borrar filtros

How to create a text file in a specific form of data arrangement

1 visualización (últimos 30 días)
Hello, I'd like to know how to create a text file that can be used as input to another program
For example, this is my data
x = [1 2 3 4 5];
q = [6 7 8 9 10];
The text file should be in the form like this
x 5
1 2 3 4 5
Data
6 7 8 9 10
All data should be displayed in a row not column form.
The headers are x 5 and Data
*5 is the data count
I tried using frprint and read all the documents related but I still don't know how to do it.
I'm very new to MATLAB. Any help would be greatly appreciated.

Respuesta aceptada

KSSV
KSSV el 4 de Oct. de 2017
x = [1 2 3 4 5];
q = [6 7 8 9 10];
fid = fopen('data.txt','w') ;
fprintf(fid,'%s %d\n','x',length(x)) ;
fprintf(fid,'\n') ;
fprintf(fid,[repmat('%f ',1,length(x)),'\n'],x') ;
fprintf(fid,'\n') ;
fprintf(fid,'%s \n','Data') ;
fprintf(fid,'\n') ;
fprintf(fid,[repmat('%f ',1,length(q)),'\n'],q') ;
fclose(fid) ;

Más respuestas (0)

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by