How to read the contents of .txt and display its contents in my gui.

6 vues (au cours des 30 derniers jours)
han han
han han le 26 Sep 2019
Commenté : Walter Roberson le 8 Fév 2025 à 8:38
How to read the contents of .txt and display its contents in my gui.
For example: I want to display the text of 1.txt to edit1, edit2, edit3 in my gui.
擷取.JPG
擷取.JPG
please help me

Réponses (1)

Aravind
Aravind le 8 Fév 2025 à 8:21
To display the contents of a .txt file in your MATLAB GUI using App Designer, you can follow the following steps.
Read the File: Use the “fopen” function to open the file, which returns a file identifier for reading. Depending on your needs, use “fread” to read the entire file as a character array or “fgets” to read the file line by line. After reading, ensure you close the file with “fclose” to free up system resources. You can learn more about these functions by using the following commands in the MATLAB Command Window:
doc fread %for fread
doc fgets %for fgets
doc fclose %for fclose
Parse the Contents: Once you have read the file, parse the contents to extract the necessary data.
Display in GUI: Use the parsed information to update the Edit Fields in your App Designer GUI. Set the “Value” property of these fields to the parsed text to display the information in the GUI. You can find more information about the "EditField" by running the following command in the MATLAB Command Window:
doc EditField
I hope this helps you achieve your goal!
  1 commentaire
Walter Roberson
Walter Roberson le 8 Fév 2025 à 8:38
In the time since the question was asked, MATLAB added a readlines function, which reads a given file name and returns a string array of text. You could then set the Value property of a uitextarea

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by