How to store a data of a structure into a text file.

1 visualización (últimos 30 días)
priyanka
priyanka el 12 de En. de 2015
Comentada: Walter Roberson el 11 de Jun. de 2021
I have created a structure in which 4 variables are defined. How to store the values of structure into a text file.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 13 de En. de 2015
Priyanka - if you just want to write the structure to file, then just try using fopen to open the file, fprintf to write the data (each of the four variables) to file, and fclose to close the file.
  2 comentarios
Aiswarya Babu
Aiswarya Babu el 11 de Jun. de 2021
help me to store data as a text file.
These are the values i need to store as a text file .
29 C3 50 5F 57 14 20 F6 40 22 99 B3 1A 02 D7 3A
Kindly help me.

Iniciar sesión para comentar.

Más respuestas (1)

samesu naq
samesu naq el 10 de Dic. de 2018
s1.name = 'fred';
s1.age = 42;
s1.height = 170;
s1(2).name = 'alice';
s1(2).age = 29;
s1(2).height = 160;
fileID = fopen('use of structure .txt','a');
fprintf(fileID, 'Missile # :%s \n', s1.name);
fprintf(fileID, 'Operator Name :%s \n', s1.age);
fprintf(fileID, 'Operator Name :%s \n', s1.height);
fprintf(fileID, 'Missile Type :%s \n', s1(2).name);
fprintf(fileID, 'Missile ID :%s \n',s1(2).age);
fprintf(fileID, 'Container Number :%s \n', s1(2).height);
fclose(fileID);
simply fprintf is not write structure variable in text file
Error occur ''Scalar structure required for this assignment.
Error in Untitled (line 36)
s1.name = 'fred';''
  1 comentario
Walter Roberson
Walter Roberson el 11 de Jun. de 2021
Editada: Walter Roberson el 11 de Jun. de 2021
s1(1).name = 'fred';
s1(1).age = 42;
s1(1).height = 170;
s1(2).name = 'alice';
s1(2).age = 29;
s1(2).height = 160;
fileID = fopen('use of structure .txt','a');
fprintf(fileID, 'Missile # :%s \n', s1(1).name);
fprintf(fileID, 'Operator Name :%s \n', s1(1).age);
fprintf(fileID, 'Operator Name :%s \n', s1(1).height);
fprintf(fileID, 'Missile Type :%s \n', s1(2).name);
fprintf(fileID, 'Missile ID :%s \n', s1(2).age);
fprintf(fileID, 'Container Number :%s \n', s1(2).height);
fclose(fileID);

Iniciar sesión para comentar.

Categorías

Más información sobre Symbolic Computations in MATLAB 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