App Designer - Writing Data to Txt File

63 visualizaciones (últimos 30 días)
I
I el 16 de Feb. de 2021
Comentada: I el 19 de Feb. de 2021
I am building a GUI using app designer and I want to be able to input data into the GUI and then write it into a text file.
The data should write as a vector
I used fprintf, but I'm no expert on app designer and it didn't seem to work.
Does anyone have an example of how to write data to a text file using app designer?

Respuestas (1)

Reshma Nerella
Reshma Nerella el 18 de Feb. de 2021
Hi,
To write data into a file, use fopen to open file. It gives a fileID to identify the open file.
Now you can write data into the file using fprintf and fileID.
Close the file using fclose after writing data into it.
For instance,
v = 1:5 %vector you want to insert
Now write it in the text file
f = fopen('filename.txt','w'); %Open or create new file for writing. Discard existing contents, if any.
fprintf(f,'%d\n',v); % Writes every element of vector in a new line in the file
fclose(f); % Close the file
Hope this helps!
  1 comentario
I
I el 19 de Feb. de 2021
I think I get how this would work, but it seems like v needs to be pre defined whereas I would like to define the variables in the form of a vector after running the app. Is it possible to proceed in this order:
  1. Run the app
  2. Define the vector
  3. Then right the matrix to the text file
Thanks for your input so far.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Export 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!

Translated by